forked from Cellule/dndGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-webpack-config.js
158 lines (152 loc) · 4.87 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var loadersByExtension = require("./config/loadersByExtension");
var joinEntry = require("./config/joinEntry");
module.exports = function(options) {
var entry = {
main: reactEntry("main"),
// second: reactEntry("second")
};
var loaders = {
"coffee": "coffee-redux-loader",
"jsx": options.hotComponents ? ["react-hot-loader", "babel-loader"] : "babel-loader",
"json": "json-loader",
"js": {
loader: "babel-loader",
include: path.join(__dirname, "app")
},
"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 stylesheetLoaders = {
"css": "css-loader",
"less": "css-loader!less-loader",
"styl": "css-loader!stylus-loader",
"scss|sass": "css-loader!sass-loader"
};
var additionalLoaders = [
// { test: /some-reg-exp$/, loader: "any-loader" }
];
var alias = {
"react-bootstrap": "react-bootstrap/lib",
};
var aliasLoader = {
};
var externals = [
];
var modulesDirectories = ["web_modules", "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", options.prerender ? "prerender" : "public"),
publicPath: publicPath,
filename: "[name].js" + (options.longTermCaching && !options.prerender ? "?[chunkhash]" : ""),
chunkFilename: (options.devServer ? "[id].js" : "[name].js") + (options.longTermCaching && !options.prerender ? "?[chunkhash]" : ""),
sourceMapFilename: "debugging/[file].map",
libraryTarget: options.prerender ? "commonjs2" : undefined,
pathinfo: options.debug
};
var excludeFromStats = [
/node_modules[\\\/]react(-router)?[\\\/]/,
/node_modules[\\\/]items-store[\\\/]/
];
var plugins = [
function() {
if(!options.prerender) {
this.plugin("done", function(stats) {
var jsonStats = stats.toJson({
chunkModules: true,
exclude: excludeFromStats
});
jsonStats.publicPath = publicPath;
require("fs").writeFileSync(path.join(__dirname, "build", "stats.json"), JSON.stringify(jsonStats));
});
}
},
new webpack.DefinePlugin({
"__DEV__": options.debug,
"__PROD__": !options.debug,
}),
new webpack.PrefetchPlugin("react"),
new webpack.PrefetchPlugin("react/lib/ReactComponentBrowserEnvironment")
];
if(options.prerender) {
aliasLoader["react-proxy$"] = "react-proxy/unavailable";
externals.push(
///^react(\/.*)?$/,
/^reflux(\/.*)?$/,
"superagent",
"async"
);
plugins.push(new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }));
}
if(options.commonsChunk) {
plugins.push(new webpack.optimize.CommonsChunkPlugin("commons", "commons.js" + (options.longTermCaching && !options.prerender ? "?[chunkhash]" : "")));
}
function reactEntry(name) {
return (options.prerender ? "./config/prerender?" : "./config/app?") + name;
}
Object.keys(stylesheetLoaders).forEach(function(ext) {
var loaders = stylesheetLoaders[ext];
if(Array.isArray(loaders)) loaders = loaders.join("!");
if(options.prerender) {
stylesheetLoaders[ext] = "null-loader";
} else if(options.separateStylesheet) {
stylesheetLoaders[ext] = ExtractTextPlugin.extract("style-loader", loaders);
} else {
stylesheetLoaders[ext] = "style-loader!" + loaders;
}
});
if(options.separateStylesheet && !options.prerender) {
plugins.push(new ExtractTextPlugin("[name].css" + (options.longTermCaching ? "?[contenthash]" : "")));
}
if(options.minimize) {
plugins.push(
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}),
new webpack.NoErrorsPlugin()
);
}
return {
entry: entry,
output: output,
target: options.prerender ? "node" : "web",
module: {
loaders: loadersByExtension(loaders).concat(loadersByExtension(stylesheetLoaders))
},
devtool: options.devtool,
debug: options.debug,
resolveLoader: {
root: path.join(__dirname, "node_modules"),
alias: aliasLoader
},
externals: externals,
resolve: {
root: root,
modulesDirectories: modulesDirectories,
extensions: extensions,
alias: alias
},
plugins: plugins,
devServer: {
stats: {
exclude: excludeFromStats
}
}
};
};