UNPKG

3.22 kBJavaScriptView Raw
1
2var path = require("path");
3var autoprefixer = require("autoprefixer");
4var webpack = require("webpack");
5var HtmlWebpackPlugin = require("html-webpack-plugin");
6var ExtractTextPlugin = require("extract-text-webpack-plugin");
7var url = require("url");
8var paths = require("./paths");
9var env = require("./env");
10
11
12if(env["process.env.NODE_ENV"] !== '"production"') {
13 throw new Error("Production builds must have NODE_ENV=production.")
14}
15var homepagePath = require(paths.appPackageJson).homepage;
16var publicPath = homepagePath ? url.parse(homepagePath).pathname : "/";
17if(!publicPath.endsWith("/")) {
18 publicPath += "/"
19}
20module.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 //include: [paths.appSrc],
51 loader: ExtractTextPlugin.extract("style", "css?-autoprefixer!postcss")
52 }, {
53 test: /\.json$/,
54 //include: [paths.appSrc, paths.appNodeModules],
55 loader: "json"
56 }, {
57 test: /\.(ico|jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
58 exclude: /\/favicon.ico$/,
59 //include: [paths.appSrc, paths.appNodeModules],
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 // require("jquery") 是引用自外部模块的
78 // 对应全局变量 jQuery
79 "jquery": true,
80 //"knockout" : "knockout",
81 //"director":"director",
82 //"polyfill":"polyfill",
83 //"bdtpl" : "bdtpl",
84 //"text":"text",
85 //"text!js/menumgr/menulist.html" : "text!js/menumgr/menulist.html"
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