-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.config.prod.js
76 lines (71 loc) · 2.01 KB
/
webpack.config.prod.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
/* global SETTINGS: false */
const webpack = require('webpack')
var path = require("path");
const fs = require('fs');
var BundleTracker = require('webpack-bundle-tracker');
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const { config, babelSharedLoader } = require(path.resolve("./webpack.config.shared.js"));
const prodBabelConfig = Object.assign({}, babelSharedLoader);
prodBabelConfig.query.plugins.push(
"transform-react-constant-elements",
"transform-react-inline-elements"
);
const filePath = path.join(__dirname, "VERSION");
const SENTRY_RELEASE = fs.readFileSync(
filePath, "utf8").split("\r?\n/")[0].trim();
const prodConfig = Object.assign({}, config);
prodConfig.module.rules = [
prodBabelConfig,
...config.module.rules,
{
test: /\.css$|\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
"css-loader",
"postcss-loader",
"sass-loader"
]
}
];
module.exports = Object.assign(prodConfig, {
context: __dirname,
mode: 'production',
output: {
path: path.resolve('./static/bundles/'),
filename: "[name]-[chunkhash].js",
chunkFilename: "[id]-[chunkhash].js",
crossOriginLoading: "anonymous",
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: '"production"'
}
}),
new BundleTracker({
filename: './webpack-stats.json'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new webpack.optimize.AggressiveMergingPlugin(),
new MiniCssExtractPlugin({
filename: "styles-[name]-[contenthash].css"
}),
...process.env.MICROMASTERS_ENVIRONMENT ? [new SentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org : process.env.SENTRY_ORG_NAME,
project : process.env.SENTRY_PROJECT_NAME,
release : SENTRY_RELEASE,
include : '.',
ignoreFile: ".gitignore"
})] : []
],
optimization: {
minimize: true
},
devtool: 'source-map'
});