抛开vue-cli,一步步搭建vue+webpack环境
https://www.jianshu.com/p/e735e67de774
这是之前写的,当时用的是webpack3
现在试着迁移到webpack4
其实只改了这些:
1、webpack4必须npm i webpack-cli(或webpack-command)不然无法运行
2、webpack.config.js有所修改
修改包括1)vueloader需要引入plugin 2)entry和output中路径写法有所改变
const path = require('path')
const VueLoader = require('vue-loader/lib/plugin') //new
module.exports = {
entry: './src/main.js', //new
output: {
path: path.resolve(__dirname, 'dist'), //new
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new VueLoader() //new
],
resolve: {
alias: {
'vue$': 'vue/dist/vue.js'
}
},
devServer: {
contentBase: 'dist',
stats: {colors: true},
historyApiFallback: true,
inline: true
}
}
其他就没什么了~~