-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwebpack.config.js
More file actions
139 lines (135 loc) · 3.75 KB
/
Copy pathwebpack.config.js
File metadata and controls
139 lines (135 loc) · 3.75 KB
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
let path = require("path");
let webpack = require("webpack");
let config = require("./config");
function loadPlugins() {
var plugins = [];
plugins.push(
// Define sentry environmental variables for client
new webpack.DefinePlugin({
BUILD_ENVIRONMENT: JSON.stringify(config.build.environment),
BUILD_RELEASE: JSON.stringify(config.build.release),
BUILD_PROTOCOL: JSON.stringify(config.build.protocol),
BUILD_DOMAINPATH: JSON.stringify(config.build.domainPath),
GOOGLE_ANALYTICS_ENABLED: JSON.stringify(config.googleAnalytics.enabled),
GOOGLE_ANALYTICS_TRACKING: JSON.stringify(config.googleAnalytics.tracking),
STRIPE_ENABLED: JSON.stringify(config.stripe.enabled),
STRIPE_API_KEY: JSON.stringify(config.stripe.apiKey),
SENTRY_ENABLED: JSON.stringify(config.sentry.enabled),
SENTRY_DSN: JSON.stringify(config.sentry.dns)
}),
new webpack.ProvidePlugin({
Promise: "imports-loader?this=>global!exports-loader?global.Promise!es6-promise",
fetch: "exports-loader?self.fetch!whatwg-fetch/dist/fetch.umd"
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en|it/)
);
if (config.build.environment === "production") {
let TerserPlugin = require("terser-webpack-plugin");
let CompressionPlugin = require("compression-webpack-plugin");
plugins.push(
new TerserPlugin({
terserOptions: {
warnings: false,
compress: true,
mangle: true,
output: {
comments: false,
beautify: false
},
toplevel: false,
keep_fnames: false,
ie8: false,
keep_classnames: undefined,
safari10: false
}
}),
new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
threshold: 10240,
minRatio: 0.8
})
);
}
if (config.build.environment === "development") {
let CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
plugins.push(new CaseSensitivePathsPlugin(), new webpack.HotModuleReplacementPlugin());
// Import BundleAnalyzer Plugin
if (config.development.analyzeBundle === true) {
let BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
plugins.push(new BundleAnalyzerPlugin());
}
}
return plugins;
}
module.exports = {
mode: config.build.environment !== "test" ? config.build.environment : "none",
entry: () => {
if (config.build.environment === "development") {
return ["@babel/polyfill", "whatwg-fetch", "./client/index.js", "webpack-hot-middleware/client", "webpack/hot/dev-server"];
} else {
return ["@babel/polyfill", "whatwg-fetch", "./client/index.js"];
}
},
output: {
path: path.join(__dirname, "distribution"),
filename: "bundle.js",
publicPath: config.build.publicPath,
hotUpdateChunkFilename: "hot/[id].[hash].hot-update.js",
hotUpdateMainFilename: "hot/[hash].hot-update.json"
},
module: {
rules: [
{
test: /.js$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
presets: ["@babel/preset-env", "@babel/preset-react"]
}
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: () => {
let postcssPresetEnv = require("postcss-preset-env");
return [postcssPresetEnv()];
}
}
},
{
loader: "sass-loader"
}
]
},
{
test: /.*\.(gif|png|jpe?g|svg)$/i,
use: [
{
loader: "file-loader",
options: {
name: "/images/[name].[ext]",
limit: 8192
}
}
]
}
]
},
plugins: config.build.environment !== "test" ? loadPlugins() : []
};