我有一个简单的项目结构:VueJS与打字稿单文件组件:无法找到模块stuff.vue
/src/app2/main.ts /src/app2/components/lib.ts /src目录/app2/components/stuff.vue
使用webpack,vue-loader和ts-loader。
main.ts有:
import Vue = require('vue');
import Component from './components/lib'
new Vue({
el: '#app2'
});
当试图与/src/app2/main.ts
1次的WebPack进入建立这个,所产生的错误是:
ERROR in C:\temp\vuetest2\proj\src\app2\components\lib.ts
(2,25): error TS2307: Cannot find module './stuff.vue'.
ERROR in ./src/app2/main.ts
Module not found: Error: Can't resolve './components/lib' in 'C:\temp\vuetest2\proj\src\app2'
@ ./src/app2/main.ts 3:12-39
如果我改变切入点src/app2/components/lib.ts
,它将建立。我不知道为什么main.ts不会构建。
lib.ts的内容:
import Vue = require('vue');
import Stuff = require('./stuff.vue');
let o = {
Stuff
}
let componentLibrary = {
components: o,
registerExternal: function(v:any) {
for(var k in o) {
v.component(o[k].name, o[k]);
}
},
registerInternal: function() {
for(var k in o) {
Vue.component(o[k].name, o[k]);
}
}
}
export default componentLibrary;
Stuff.vue只是一个简单的单个文件VUE组件。
尝试修改main.ts,像这样的'新的Vue({ EL: '#APP 2', 渲染:(H)=> H(组件) });'我想'Component'是主组件 –
它不会在webpack中编译。就我所知,你的建议对编辑没有什么影响。 – lucuma
你有没有想过这个? – pulekies