-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
99 lines (89 loc) · 2.31 KB
/
webpack.config.babel.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
/* global process */
import webpack from "webpack";
import path from "path";
import basscss from "postcss-basscss";
import cssnext from "cssnext";
import HtmlWebpackPlugin from "html-webpack-plugin";
import CleanWebpackPlugin from "clean-webpack-plugin";
const env = process.env.NODE_ENV;
const isDev = (env === "development");
const publicPath = isDev ? "/" : "static/starter-project";
const devtool = isDev ? "#source-map" : null;
const postcss = () => {
return [
basscss({
raw: true,
}),
cssnext({
compress: true,
features: {
rem: false,
pseudoElements: false,
},
}),
];
};
const plugins = [
new HtmlWebpackPlugin({
template: path.join(__dirname, "/app/index.ejs"),
filename: "index.html",
}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
];
const entry = ["./index.jsx"];
const jsLoaders = ["babel"];
if (!isDev) {
plugins.unshift(new CleanWebpackPlugin(["build"]));
}
if (isDev) {
plugins.push(
new webpack.HotModuleReplacementPlugin()
);
entry.unshift(
"webpack-dev-server/client?http://0.0.0.0:8080",
"webpack/hot/only-dev-server",
);
jsLoaders.unshift("react-hot");
}
module.exports = {
context: path.join(__dirname, "/app"),
entry,
output: {
path: path.join(__dirname, "/build"),
filename: "bundle.[hash].js",
publicPath,
},
resolve: {
root: [path.join(__dirname, "app")],
extensions: ["", ".js", ".jsx", ".css"],
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: jsLoaders,
}, {
test: /\.json$/,
loader: "json",
}, {
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader",
}, {
test: /\.scss$/,
loaders: ["style", "css", "sass"],
}, {
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: "url-loader?limit=1000000",
}, {
test: /\.(png|jpg)$/,
loader: "file-loader?name=assets/images/[name].[ext]",
}],
},
postcss,
devtool,
plugins,
};