加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
webpack.config.js 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
思伟 提交于 2019-07-23 15:52 . 更新配置及代码
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: "./source",
publicPath: "./",
filename: "[name].[chunkhash:6].js"
},
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader?cacheDirectory',
exclude: /node_modules/
}, {
test: /\.html$/,
loader: 'html'
}, {
test: /\.(scss|sass|css)$/,
loader: ExtractTextPlugin.extract('style-loader', ['css-loader?-autoprefixer', 'postcss-loader', 'sass-loader'])
}, {
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]"
}]
},
alias: {
'vue$': 'vue/dist/vue.js'
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.common.js'
}
},
// devtool: '#eval-source-map',
postcss: function () {
return [autoprefixer];
},
plugins: [
new ExtractTextPlugin('[name].[chunkhash:6].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'
}),
new HtmlWebpackPlugin({
inject: false,
cache: false,
minify: minifyHTML,
template: './source-src/css.ejs',
filename: '../layout/_partial/css.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')
])
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化