This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
135 lines (123 loc) · 3.14 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
const glob = require("glob");
const path = require("path");
const _ = require("lodash");
const webpack = require("webpack");
const autoprefixer = require("autoprefixer");
const HappyPack = require("happypack");
const moment = require("moment");
const isProduction = () => process.env.NODE_ENV === "production";
let plugins = [
new HappyPack({
id: "jsx",
threads: 4,
loaders: [
{
loader: require.resolve("babel-loader"),
query: {
plugins: [require.resolve("react-hot-loader/babel")],
},
},
],
}),
new HappyPack({
id: "styles",
threads: 2,
loaders: [
{ loader: require.resolve("style-loader") },
{ loader: require.resolve("css-loader") },
{ loader: require.resolve("sass-loader") },
{
loader: require.resolve("postcss-loader"),
options: {
indent: "postcss",
plugins: () => [
require("postcss-flexbugs-fixes"), // eslint-disable-line
autoprefixer({
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9", // React doesn't support IE8 anyway
],
flexbox: "no-2009",
}),
],
},
},
],
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en/),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
BUILD_DATE: JSON.stringify(moment().format("MMMM, DD, YYYY, HH:mm:ss")),
GIT_COMMIT: JSON.stringify(process.env.CIRCLE_SHA1 || ""),
},
}),
new webpack.SourceMapDevToolPlugin({ filename: "[file].map" }),
];
if (isProduction()) {
plugins = [
...plugins,
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: { warnings: false, screw_ie8: false },
}),
];
}
const entry = _.reduce(
glob.sync(path.join(process.cwd(), "src/*.js")),
(m, v) => {
m[
v
.split("/")
.pop()
.replace(".js", "")
] = v;
return m;
},
{}
);
module.exports = {
devtool: isProduction() ? "source-map" : "inline-source-map",
performance: {
hints: isProduction() ? "warning" : false,
},
entry,
output: {
path: path.join(process.cwd(), "dist"),
filename: "[name].js",
publicPath: "/",
},
plugins,
resolve: {
modules: [path.join(process.cwd(), "src"), "node_modules"],
extensions: [".js", ".jsx", ".css", ".scss"],
},
resolveLoader: {
modules: ["node_modules", path.join(process.cwd(), "node_modules")],
},
module: {
rules: [
{
test: /\.jsx|\.js$/,
loader: require.resolve("happypack/loader"),
query: { id: "jsx" },
exclude: /node_modules/,
},
// styles
{
test: /\.(css|scss)$/,
loader: require.resolve("happypack/loader"),
query: { id: "styles" },
},
// svg
{ test: /.svg$/, loader: "svg-inline-loader" },
// images & other files
{
test: /\.jpe?g$|\.gif$|\.png|\.woff$|\.ttf$|\.wav$|\.mp3$/,
loader: "file-loader",
},
],
},
};