-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-webpack-config.js
137 lines (124 loc) · 4.04 KB
/
make-webpack-config.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var StatsPlugin = require("stats-webpack-plugin");
var loadersByExtension = require("./config/loadersByExtension");
module.exports = function(options) {
var entry = {
main: "./app/client"
};
var loaders = {
"jsx": options.hotComponents ? ["react-hot-loader", "babel-loader?stage=0"] : "babel-loader?stage=0",
"js": {
loader: "babel-loader?stage=0",
include: path.join(__dirname, "app")
},
"json": "json-loader",
"json5": "json5-loader",
"txt": "raw-loader",
"png|jpg|jpeg|gif|svg": "url-loader?limit=10000",
"woff|woff2": "url-loader?limit=100000",
"ttf|eot": "file-loader",
"wav|mp3": "file-loader",
"html": "html-loader",
"md|markdown": ["html-loader", "markdown-loader"]
};
var cssLoader = options.minimize ? "css-loader?module" : "css-loader?module&localIdentName=[path][name]---[local]---[hash:base64:5]";
var stylesheetLoaders = {
"css": cssLoader,
"less": [cssLoader, "less-loader"],
"styl": [cssLoader, "stylus-loader"],
"scss|sass": [cssLoader, "sass-loader"]
};
var additionalLoaders = [
// { test: /some-reg-exp$/, loader: "any-loader" }
];
var modulesDirectories = [ "node_modules" ];
var extensions = ["", ".web.js", ".js", ".jsx"];
var root = path.join(__dirname, "app");
var publicPath = options.devServer ?
"http://localhost:2992/_assets/" :
"/_assets/";
var output = {
path: path.join(__dirname, "build", "public"),
publicPath: publicPath,
filename: "[name].js" + (options.longTermCaching ? "?[chunkhash]" : ""),
chunkFilename: (options.devServer ? "[id].js" : "[name].js") + (options.longTermCaching ? "?[chunkhash]" : ""),
sourceMapFilename: "debugging/[file].map",
pathinfo: options.debug
};
var excludeFromStats = [
/node_modules[\\\/]react(-router)?[\\\/]/
];
var plugins = [
new webpack.PrefetchPlugin("react"),
new webpack.PrefetchPlugin("react/lib/ReactComponentBrowserEnvironment"),
new StatsPlugin(path.join(__dirname, "build", "stats.json"), {
chunkModules: true,
exclude: excludeFromStats
})
];
if (options.debug) {
plugins.push(new webpack.DefinePlugin({
__DEVTOOLS__ : true,
__DEVELOPMENT__: true,
}));
}
if (options.commonsChunk) {
//TODO: investigate necesit of this, do i need commons entry?
plugins.push(new webpack.optimize.CommonsChunkPlugin(
"commons", "commons.js" + (options.longTermCaching ? "?[chunkhash]" : "")));
}
Object.keys(stylesheetLoaders).forEach(function(ext) {
var stylesheetLoader = stylesheetLoaders[ext];
if(Array.isArray(stylesheetLoader)) stylesheetLoader = stylesheetLoader.join("!");
if(options.separateStylesheet) {
stylesheetLoaders[ext] = ExtractTextPlugin.extract("style-loader", stylesheetLoader);
} else {
stylesheetLoaders[ext] = "style-loader!" + stylesheetLoader;
}
});
if(options.separateStylesheet) {
plugins.push(new ExtractTextPlugin("[name].css" + (options.longTermCaching ? "?[contenthash]" : "")));
}
//TODO this doesn't seem to be minfiying
if(options.minimize) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new webpack.NoErrorsPlugin()
);
}
return {
entry: entry,
output: output,
module: {
loaders: loadersByExtension(loaders).concat(loadersByExtension(stylesheetLoaders)).concat(additionalLoaders)
},
debug: options.debug,
resolveLoader: {
root: path.join(__dirname, "node_modules")
},
resolve: {
root: root,
modulesDirectories: modulesDirectories,
extensions: extensions
},
plugins: plugins,
devServer: {
stats: {
cached: false,
exclude: excludeFromStats
}
}
}
}