Closed zhoukekestar closed 7 years ago
源码中的vue-loader
版本需要 12.0.1
, 用了13.0.1
的,是不行,踩坑特别提醒。具体看源码。
看了最新的 vue-loader
后,发现这个webpack
的一个更新,需要在插件中,更换成factory().default
:
class UMDPlugin {
apply(compiler) {
compiler.plugin('emit', (compilation, callback) => {
Object.keys(compilation.assets).map(file => {
if (/\.js$/.test(file)) {
let source = `${compilation.assets[file].source()}`;
source = source.replace(/root\["(\S*?)"\] = factory\(\);/g, (s, name) => `root.Vue && root.Vue.component("${name.replace(/\S*?\\/, '')}", factory().default);`);
compilation.assets[file] = {
source: () => source,
size: () => source.length,
};
}
});
callback();
});
}
}
https://zhoukekestar.github.io/notes/2017/07/10/how-to-write-non-spa-with-vue.html