1 |
|
2 | var path = require("path");
|
3 | var autoprefixer = require("autoprefixer");
|
4 | var webpack = require("webpack");
|
5 | var HtmlWebpackPlugin = require("html-webpack-plugin");
|
6 | var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
7 | var url = require("url");
|
8 | var paths = require("./paths");
|
9 | var env = require("./env");
|
10 |
|
11 |
|
12 | if(env["process.env.NODE_ENV"] !== '"production"') {
|
13 | throw new Error("Production builds must have NODE_ENV=production.")
|
14 | }
|
15 | var homepagePath = require(paths.appPackageJson).homepage;
|
16 | var publicPath = homepagePath ? url.parse(homepagePath).pathname : "/";
|
17 | if(!publicPath.endsWith("/")) {
|
18 | publicPath += "/"
|
19 | }
|
20 | module.exports = {
|
21 | bail: true,
|
22 | devtool: "source-map",
|
23 | entry: [path.join(paths.appSrc, "index")],
|
24 | output: {
|
25 | path: paths.appBuild,
|
26 | filename: "static/js/[name].[chunkhash:8].js",
|
27 | chunkFilename: "static/js/[name].[chunkhash:8].chunk.js",
|
28 | publicPath: publicPath
|
29 | },
|
30 | resolve: {
|
31 | extensions: [".js", ".json", ""],
|
32 | alias: {
|
33 | "babel-runtime/regenerator": require.resolve("babel-runtime/regenerator"),
|
34 | "react-native": "react-native-web"
|
35 | }
|
36 | },
|
37 | resolveLoader: {
|
38 | root: paths.ownNodeModules,
|
39 | moduleTemplates: ["*-loader"]
|
40 | },
|
41 | module: {
|
42 | preLoaders: [],
|
43 | loaders: [{
|
44 | test: /\.js$/,
|
45 | include: paths.appSrc,
|
46 | loader: "babel",
|
47 | query: require("./babel.prod")
|
48 | }, {
|
49 | test: /\.css$/,
|
50 |
|
51 | loader: ExtractTextPlugin.extract("style", "css?-autoprefixer!postcss")
|
52 | }, {
|
53 | test: /\.json$/,
|
54 |
|
55 | loader: "json"
|
56 | }, {
|
57 | test: /\.(ico|jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
|
58 | exclude: /\/favicon.ico$/,
|
59 |
|
60 | loader: "file",
|
61 | query: {
|
62 | name: "static/media/[name].[hash:8].[ext]"
|
63 | }
|
64 | }, {
|
65 | test: /\/favicon.ico$/,
|
66 | include: [paths.appSrc],
|
67 | loader: "file",
|
68 | query: {
|
69 | name: "favicon.ico?[hash:8]"
|
70 | }
|
71 | },{
|
72 | test: /\.html$/,
|
73 | loader: "html"
|
74 | }]
|
75 | },
|
76 | externals: {
|
77 |
|
78 |
|
79 | "jquery": true,
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | },
|
87 | eslint: {},
|
88 | postcss: function() {
|
89 | return [autoprefixer({
|
90 | browsers: [">1%", "last 4 versions", "Firefox ESR", "not ie < 9", ]
|
91 | }), ]
|
92 | },
|
93 | plugins: [new HtmlWebpackPlugin({
|
94 | inject: true,
|
95 | template: paths.appHtml,
|
96 | minify: {
|
97 | removeComments: true,
|
98 | collapseWhitespace: true,
|
99 | removeRedundantAttributes: true,
|
100 | useShortDoctype: true,
|
101 | removeEmptyAttributes: true,
|
102 | removeStyleLinkTypeAttributes: true,
|
103 | keepClosingSlash: true,
|
104 | minifyJS: true,
|
105 | minifyCSS: true,
|
106 | minifyURLs: true
|
107 | }
|
108 | }), new webpack.DefinePlugin(env), new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({
|
109 | compress: {
|
110 | screw_ie8: true,
|
111 | warnings: false
|
112 | },
|
113 | mangle: {
|
114 | screw_ie8: true
|
115 | },
|
116 | output: {
|
117 | comments: false,
|
118 | screw_ie8: true
|
119 | }
|
120 | }), new ExtractTextPlugin("static/css/[name].[contenthash:8].css")]
|
121 | }; |
\ | No newline at end of file |