-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
50 lines (45 loc) · 1.34 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
const Path = require('path');
const { JavascriptWebpackConfig, CssWebpackConfig } = require('@silverstripe/webpack-config');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ENV = process.env.NODE_ENV;
const PATHS = {
ROOT: Path.resolve(),
SRC: Path.resolve('client/src'),
DIST: Path.resolve('client/dist'),
};
// Frontend JS bundle
const frontendJsConfig = new JavascriptWebpackConfig('js', PATHS, 'silverstripe/totp-authenticator')
.setEntry({
bundle: `${PATHS.SRC}/bundles/bundle.js`,
})
.mergeConfig({
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: `${PATHS.SRC}/images`,
to: `${PATHS.DIST}/images`,
},
]
}),
],
})
.getConfig();
// Only include a single "external" which is actually added to the DOM separately
// Don't include any other externals as this will be used on the frontend
frontendJsConfig.externals = {
'lib/Injector': 'Injector',
};
const config = [
frontendJsConfig,
// sass to css
new CssWebpackConfig('css', PATHS)
.setEntry({
bundle: `${PATHS.SRC}/bundles/bundle.scss`,
})
.getConfig(),
];
// Use WEBPACK_CHILD=js or WEBPACK_CHILD=css env var to run a single config
module.exports = (process.env.WEBPACK_CHILD)
? config.find((entry) => entry.name === process.env.WEBPACK_CHILD)
: config;