This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
webpack.config.js
79 lines (72 loc) · 2.35 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
/*eslint-env node*/
/*eslint import/no-nodejs-modules:0 */
const path = require('path');
const webpack = require('webpack');
const babelConfig = require('./babel.config');
const CompressionPlugin = require('compression-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const APPS = [];
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const WEBPACK_MODE = IS_PRODUCTION ? 'production' : 'development';
function getConfig(app) {
const pyName = app.replace('-', '_');
const staticPrefix = `src/sentry_plugins/${pyName}/static/${pyName}`;
const distPath = `${staticPrefix}/dist`;
const config = {
mode: WEBPACK_MODE,
name: app,
entry: `./${pyName}.jsx`,
context: path.join(__dirname, staticPrefix),
externals: {
react: 'React',
'react-dom': 'ReactDOM',
'react-router': 'Router',
reflux: 'Reflux',
moment: 'moment',
sentry: 'SentryApp',
'prop-types': 'PropTypes'
},
module: {
rules: [
{
test: /\.jsx?$/,
include: path.join(__dirname, staticPrefix),
exclude: /(vendor|node_modules)/,
use: [
{
loader: 'babel-loader',
// Disable loading the configFile for when plugins are being
// built by a webpack devserver *outside* of this directory.
// Otherwise the loader will try and locate the babel.config.js
// file, which will be sentry or getsentrys.
options: {...babelConfig, configFile: false}
}
]
}
]
},
plugins: [new LodashModuleReplacementPlugin()],
resolve: {
extensions: ['*', '.jsx', '.js']
},
output: {
path: path.join(__dirname, distPath),
filename: `${app}.js`,
sourceMapFilename: `${app}.js.map`
},
devtool: IS_PRODUCTION ? 'source-map' : 'cheap-module-eval-source-map'
};
// This compression-webpack-plugin generates pre-compressed files
// ending in .gz, to be picked up and served by our internal static media
// server as well as nginx when paired with the gzip_static module.
if (IS_PRODUCTION) {
config.plugins.push(
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|map|css|svg|html|txt|ico|eot|ttf)$/
})
);
}
return config;
}
module.exports = APPS.map(getConfig);