-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.browser.js
49 lines (46 loc) · 1.48 KB
/
webpack.browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const merge = require("webpack-merge");
const common = require("./webpack.common.js");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CleanWebpackPlugin = require('clean-webpack-plugin');
const path = require("path");
const {PATHS} = require('./project-config');
const devMode = process.env.NODE_ENV !== "production";
let plugs = [
new HtmlWebpackPlugin({
title: "react 全家桶",
template: "src/index.html"
})
];
if (!devMode) {
plugs = plugs.concat([
new CleanWebpackPlugin(['dist']),
new UglifyJSPlugin({
uglifyOptions: {
compress: {
drop_console: true // 是否删除代码中所有的console
}
}
}),
new OptimizeCSSAssetsPlugin({}),
// new webpack.DefinePlugin({
// 'process.env.NODE_ENV': JSON.stringify('production')
// }),
]);
}
module.exports = merge(common, {
devtool: devMode ? "inline-source-map" : false,
entry: {
app: ["babel-polyfill", PATHS.index]
},
output: {
path: path.resolve(__dirname, PATHS.output),
publicPath: PATHS.publicPath,
filename: devMode ? "[name].js" : "[name].[chunkhash].js",
chunkFilename: devMode ? "[name].bundle.js" : "[name].[chunkhash].js"
},
plugins: plugs
});