77 lines
2.0 KiB
JavaScript
77 lines
2.0 KiB
JavaScript
var webpack = require("webpack");
|
||
var autoprefixer = require('autoprefixer');
|
||
var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
||
var CleanPlugin = require('clean-webpack-plugin');
|
||
|
||
// 模板压缩
|
||
// 详见:https://github.com/kangax/html-minifier#options-quick-reference
|
||
|
||
var minifyHTML = {
|
||
collapseInlineTagWhitespace: true,
|
||
collapseWhitespace: true,
|
||
minifyJS:true
|
||
}
|
||
|
||
module.exports = {
|
||
entry: {
|
||
main: "./source-src/js/main.js",
|
||
slider: "./source-src/js/slider.js",
|
||
mobile: ["babel-polyfill", "./source-src/js/mobile.js"]
|
||
},
|
||
output: {
|
||
path: __dirname+"/source",
|
||
filename: "js/[name].[chunkhash].js"
|
||
},
|
||
module: {
|
||
loaders: [{
|
||
test: /\.js$/,
|
||
loader: 'babel-loader?cacheDirectory',
|
||
exclude: /node_modules/
|
||
}, {
|
||
test: /\.html$/,
|
||
loader: 'html'
|
||
}, {
|
||
test: /\.(scss|sass|css)$/,
|
||
loader: ExtractTextPlugin.extract({fallback:"style-loader",use:["css-loader","postcss-loader","sass-loader?outputStyle=compressed"]})
|
||
}, {
|
||
test: /\.(gif|jpg|png)\??.*$/,
|
||
loader: 'url-loader?limit=500&name=img/[name].[ext]'
|
||
}, {
|
||
test: /\.(woff|svg|eot|ttf)\??.*$/,
|
||
loader: "file-loader?name=fonts/[name].[hash:6].[ext]"
|
||
}]
|
||
},
|
||
plugins: [
|
||
new ExtractTextPlugin('style.css'),
|
||
new webpack.DefinePlugin({
|
||
'process.env.NODE_ENV': '"production"'
|
||
}),
|
||
new HtmlWebpackPlugin({
|
||
inject: false,
|
||
cache: false,
|
||
minify: minifyHTML,
|
||
template: './source-src/script.ejs',
|
||
filename: '../layout/_partial/script.ejs'
|
||
})
|
||
],
|
||
watch: true
|
||
}
|
||
|
||
if (process.env.NODE_ENV === 'production') {
|
||
module.exports.devtool = '#source-map'
|
||
module.exports.plugins = (module.exports.plugins || []).concat([
|
||
new webpack.DefinePlugin({
|
||
'process.env': {
|
||
NODE_ENV: '"production"'
|
||
}
|
||
}),
|
||
new webpack.optimize.UglifyJsPlugin({
|
||
compress: {
|
||
warnings: false
|
||
}
|
||
}),
|
||
new webpack.optimize.OccurenceOrderPlugin(),
|
||
new CleanPlugin('builds')
|
||
])
|
||
} |