-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
139 lines (122 loc) · 3.5 KB
/
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
const path = require("path");
// const HtmlwebpackPlugin = require("html-webpack-plugin");
const webpack = require("webpack");
const merge = require("webpack-merge");
const TARGET = process.env.npm_lifecycle_event;
const ROOT_PATH = path.resolve(__dirname);
const BUILDJSPATH = "js/vendor.js";
const common = {
output: {
path: path.resolve(ROOT_PATH, "build"),
filename: "js/bundle.js"
}
};
if (TARGET === "build") {
module.exports = merge(common, {
entry: {
app: path.resolve(ROOT_PATH, "app/app.jsx"),
vendor: ["react", "jquery", "jquery-ui"]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
filename: BUILDJSPATH,
minChunks: module => {
const userRequest = module.userRequest;
// module.userRequest returns name of file, including path
return userRequest && userRequest.match(/\.js$/) && userRequest.indexOf("node_modules") >= 0;
}
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"root.jQuery": "jquery"
})
],
devtool: "source-map",
module: {
// Note: don"t include the same loader in multiple places, e.g putting babel under "common" and here.
// Webpack will error out if you try this.
loaders: [{
test: /\.jsx?$/,
loaders: ["babel-loader"],
include: path.resolve(ROOT_PATH, "app")
}]
}
});
}
if (TARGET === "buildmin") {
module.exports = merge(common, {
entry: {
app: path.resolve(ROOT_PATH, "app/app.jsx")
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
filename: BUILDJSPATH,
minChunks: module => {
const userRequest = module.userRequest;
// module.userRequest returns name of file, including path
return userRequest && userRequest.match(/\.js$/) && userRequest.indexOf("node_modules") >= 0;
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"root.jQuery": "jquery"
})
],
devtool: "source-map",
module: {
// Note: don"t include the same loader in multiple places, e.g putting babel under "common" and here.
// Webpack will error out if you try this.
loaders: [{
test: /\.jsx?$/,
loaders: ["babel-loader"],
include: path.resolve(ROOT_PATH, "app")
}]
}
});
}
const devServerCommon = {
entry: {
app: [path.resolve(ROOT_PATH, "app/app.jsx")]
},
devServer: {
noInfo: false,
historyApiFallback: true,
hot: true
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"root.jQuery": "jquery"
})
]
};
const startCommon = merge(common, devServerCommon);
if (TARGET === "start" || !TARGET) {
// react-hot loader used, with full(ish) eval source maps generated.
module.exports = merge(startCommon, {
devtool: "eval-source-map",
module: {
// Note: don"t include the same loader in multiple places, e.g putting babel under "common" and here.
// Webpack will error out if you try this.
loaders: [{
test: /\.jsx?$/,
loaders: ["babel-loader"],
include: path.resolve(ROOT_PATH, "app")
}]
}
});
}