package.json腳本
"scripts": {
"clean": "rimraf ./build && mkdir build",
"gulp": "gulp",
"prebuild": "npm run clean && npm run gulp",
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot --host 10.20.102.73",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules ",
"postbuild":"npm run gulpzip && npm run cleanFolder",
"gulpzip":"gulp zip",
"cleanFolder":"rimraf ./build"
},
webpack打包壓縮配置
var path = require('path')
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = {
entry: {
'login': './js/login.js',
'register': './js/register.js',
'retrievepwd': './js/retrievepwd.js'
},
output: {
path: __dirname + '/build',
filename: 'js/[name].[hash].js',
publicPath:'/'
},
module: {
rules: [
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader?limit=8192&name=./img/[name].[ext]&outputPath=img/"'
},
{
test: /\.css$/,
loader: ['style-loader', 'css-loader'],
},
{
test: /\.less$/i,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'less-loader']
}),
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
]
},
devServer: {
historyApiFallback: true,
noInfo: true
},
performance: {
hints: false
},
devtool: '#eval-source-map',
plugins: [
new HtmlWebpackPlugin({
favicon: './img/favicon.ico',
template: './login.html',
filename: 'login.html',
chunks: ['login'],
inject: true,
minify: {
removeComments: true,
}
}),
new HtmlWebpackPlugin({
favicon: './img/favicon.ico',
template: './register.html',
filename: 'register.html',
chunks: ['register'],
inject: true,
minify: {
removeComments: true,
}
}),
new HtmlWebpackPlugin({
favicon: './img/favicon.ico',
template: './retrievePwd.html',
filename: 'retrievePwd.html',
chunks: ['retrievepwd'],
inject: true,
minify: {
removeComments: true,
}
}),
new ExtractTextPlugin('css/main.[hash].css')
]
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
])
}