-
Notifications
You must be signed in to change notification settings - Fork 89
/
webpack.config.js
96 lines (89 loc) · 2.7 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
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const loaders = require('./webpack.loaders');
const pkg = require('./package.json');
const { eslint, babel, globalCss, localCss, font } = loaders;
const env =
(!!process.env.BABEL_ENV && process.env.BABEL_ENV) ||
(!!process.env.NODE_ENV && process.env.NODE_ENV) ||
'development';
console.log(`NODE_ENV set to: ${env}`);
let assets = process.env.MARGE_ASSETS;
if (assets !== 'inline' && assets !== 'external') {
assets = 'external';
}
const isDev = env === 'development';
const fontLimit = assets === 'external' ? 1000 : 100000;
const cssFilename = assets === 'inline' ? '[name].inline.css' : '[name].css';
const plugins = [
new StyleLintPlugin({
context: 'src',
files: '**/*.css',
color: true,
emitErrors: false,
}),
new MiniCssExtractPlugin({ filename: cssFilename, allChunks: true }),
new webpack.BannerPlugin(
`mochawesome-report-generator ${
pkg.version
} | https://github.com/adamgruber/mochawesome-report-generator`
),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(env) }),
];
module.exports = {
mode: env,
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers':
'X-Requested-With, content-type, Authorization',
},
},
devtool: isDev ? 'source-map' : false,
entry: {
app: './src/client/js/mochawesome.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: isDev ? 'http://localhost:8080/' : '',
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.json', '.jsx', '.css'],
modules: ['node_modules', 'src', 'src/client', 'styles'],
},
module: {
rules: [
eslint({ enforce: 'pre' }),
babel({}, pkg.version),
globalCss({
importLoaders: 1,
sourceMap: isDev,
}),
localCss({
modules: true,
importLoaders: 1,
localIdentName: isDev
? '[name]--[local]'
: '[name]--[local]---[hash:base64:5]',
sourceMap: isDev,
}),
font('woff', { limit: fontLimit }),
font('ttf', { limit: fontLimit }),
font('svg', { limit: fontLimit }),
],
},
optimization: {
minimize: env === 'production',
minimizer: [new TerserPlugin({
extractComments: {
banner: () => `mochawesome-report-generator ${pkg.version} | https://github.com/adamgruber/mochawesome-report-generator`,
},
})],
},
plugins,
};