forked from adamgruber/mochawesome-report-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (88 loc) · 2.66 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
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-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';
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 ExtractTextPlugin({ filename: cssFilename, allChunks: true }),
new webpack.BannerPlugin(`mochawesome-report-generator ${pkg.version} | https://github.com/adamgruber/mochawesome-report-generator`)
];
if (env === 'production') {
plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}));
plugins.push(new UglifyJsPlugin({
uglifyOptions: {
compress: { warnings: false },
output: {
comments: /^! mochawesome/,
inline_script: true
},
}
}));
}
module.exports = {
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' : '',
entry: {
app: './src/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',
'components',
'styles'
]
},
module: {
rules: [
eslint({ enforce: 'pre' }),
babel({}, pkg.version),
globalCss({
minimize: true,
importLoaders: 1,
sourceMap: isDev
}),
localCss({
minimize: true,
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 })
]
},
plugins
};