vue配置文件分离
1.安装插件webpack-merge
npm install --save-dev webpack-merge
2.创建要分离出的配置信息文件比如:共有的base.config.js
注意:path路径
const path = require('path');
module.exports = {
entry: './src/main.js',
output:{
path: path.resolve(__dirname,'../dist'),
filename: 'bundle.js',
publicPath: 'dist/'
},
module: {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /\.vue$/,
user: ['vue-loader']
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 500
}
}
]
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}
},
{
test: /\.less$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader" // compiles Less to CSS
}]
},
]
},
resolve: {
alias:{
'vue$': 'vue/dist/vue.esm.js'
}
},
}
3.配置dev.json.js
const UgligyjsWebpackPlugin = require('uglifyjd-webpack-plugin')
const WebpackMerge = require('webpack-merge')
const BaseConfig = require('./base.config.js')
module.exports = WebpackMerge(BaseConfig,{
plugins: [
new UgligyjsWebpackPlugin(),
]
})
4.配置prod.config.js和步骤3一样.
4.指定要用哪一个配置文件
webpack.json
"build" : "webpack --config ./build/prod.config.js"
"dev" : "webpack --config ./config/dev.config.js"