-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.babel.js
123 lines (116 loc) · 3.03 KB
/
webpack.config.babel.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
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
import path from 'path';
import EventEmitter from 'events';
import WebpackNotifierPlugin from 'webpack-notifier';
import RemovePlugin from 'remove-files-webpack-plugin';
import { ProvidePlugin } from 'webpack';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import PlayFingerprintsPlugin from './build-tooling/PlayFingerprintsPlugin';
import WatchEventsPlugin from './build-tooling/WatchEventsPlugin';
const merge = require('webpack-merge');
const tooling = require('./build-tooling/webpack.tooling');
const paths = {
ROOT: __dirname,
RELATIVE_ASSETS: 'target/assets',
ASSETS: path.join(__dirname, 'target/assets'),
NODE_MODULES: path.join(__dirname, 'node_modules/@universityofwarwick/id7'),
ID7: path.join(__dirname, 'node_modules/@universityofwarwick/id7'),
ENTRY: './app/assets/js/main.js',
PUBLIC_PATH: '/assets/',
};
const commonConfig = merge([
{
output: {
path: paths.ASSETS,
publicPath: paths.PUBLIC_PATH,
},
node: {
// Fix Webpack global CSP violation https://github.com/webpack/webpack/issues/6461
global: false,
},
plugins: [
// Fix Webpack global CSP violation https://github.com/webpack/webpack/issues/6461
new ProvidePlugin({
global: require.resolve('./build-tooling/global.js'),
}),
new PlayFingerprintsPlugin(),
new RemovePlugin({
before: {
root: paths.ROOT,
include: [paths.RELATIVE_ASSETS],
},
after: {
root: paths.ROOT,
test: [
{
folder: paths.RELATIVE_ASSETS,
method: filePath => (new RegExp(/style\.js.*$/, 'm').test(filePath)),
},
],
},
}),
],
resolve: {
alias: {
id7: paths.ID7,
},
},
externals: {
jquery: 'jQuery',
},
},
tooling.lintJS(),
tooling.transpileJS({
entry: {
main: paths.ENTRY,
},
include: [
/node_modules\/@universityofwarwick/,
/app\/assets\/js/,
],
}),
tooling.copyNpmDistAssets({
dest: path.join(paths.ASSETS, 'lib'),
modules: ['@universityofwarwick/id7'],
}),
{
plugins: [
new CopyWebpackPlugin([{
from: 'node_modules/@fortawesome/fontawesome-free/webfonts',
to: path.join(paths.ASSETS, 'lib/fontawesome-free/webfonts'),
}]),
],
},
tooling.copyLocalImages({
dest: paths.ASSETS,
}),
tooling.extractCSS({
resolverPaths: [
paths.NODE_MODULES,
],
}),
]);
const productionConfig = merge([
{
mode: 'production',
},
tooling.transpileJS(),
tooling.minify(),
tooling.generateSourceMaps('source-map'),
]);
const developmentConfig = merge([
{
mode: 'development',
plugins: [
new WebpackNotifierPlugin(),
new WatchEventsPlugin({ emitter: new EventEmitter() }),
],
},
tooling.generateSourceMaps('cheap-module-source-map'),
]);
module.exports = ({ production } = {}) => {
if (production) {
return merge(commonConfig, productionConfig);
} else {
return merge(commonConfig, developmentConfig);
}
};