Skip to content

动态引入组件转换

替换动态组件。

比如下面的动态组件:

ts
components: {
  xxComp(resolve) {
    require(['xx.comp'], resolve);
  },
}

会被转为:

ts
import xxComp from 'xx.comp';

components: {
  xxComp,
}

如何使用

安装

bash
pnpm add @plugin-light/webpack-loader-transform-dynamic-comp -D

vue.config.js 中添加如下设置:

js
const { LOADER: transformDynamicComp } = require('@plugin-light/webpack-loader-transform-dynamic-comp');

module.export = {
  chainWebpack(config) {
    config.module
      .rule('vue')
      .test(/\.vue$/)
      .use(transformDynamicComp)
      .loader(transformDynamicComp)
      .end();
  }
}

更新日志

点此查看