我制作了一个vue组件包my-custom-comp
,其中包含动态导入:
my-custom-comp.vue
<template>
<component v-if="id && data" :is="`list-${id}`" :data="data" />
</template>
<script>
export default {
props: ['id','data'],
components: {
'list-1': () => import(/* webpackChunkName: "MyTaglist0" */'./list-1.vue'),
'list-2': () => import(/* webpackChunkName: "MyTaglist0" */'./list-2.vue'),
'list-3': () => import(/* webpackChunkName: "MyTaglist1" */'./list-3.vue'),
'list-4': () => import(/* webpackChunkName: "MyTaglist1" */'./list-4.vue')
}
}
</script>
lib中的输出文件:
my-custom-comp.common.js
my-custom-comp.common.MyTaglist0.js
my-custom-comp.common.MyTaglist1.js
我的应用中安装了my-custom-comp
软件包,并将软件包路径添加到resolve.modules
:
webpack.config.js
module.exports = {
...
resolve: {
modules: [path.join(__dirname, '../node_modules'), path.join(__dirname, '../node_modules/my-custom-comp/lib')],
}
...
}
但是MyTaglist0.js
无法解决:
GET http://localhost:8882/my-custom-comp.common.MyTaglist0.js net::ERR_ABORTED 404 (Not Found)
如何解决从node_modules动态导入?