forked from silverstripe/silverstripe-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
129 lines (126 loc) · 3.79 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
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
124
125
126
127
128
129
const Path = require('path');
const webpack = require('webpack');
const webpackConfig = require('@silverstripe/webpack-config');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {
resolveJS,
externalJS,
moduleJS,
pluginJS,
moduleCSS,
pluginCSS,
} = webpackConfig;
const ENV = process.env.NODE_ENV;
const PATHS = require('./webpack-vars');
const config = [
{
name: 'js',
entry: {
bundle: `${PATHS.SRC}/bundles/bundle.js`,
vendor: `${PATHS.SRC}/bundles/vendor.js`,
// legacy scripts
'LeftAndMain.Ping': `${PATHS.LEGACY_SRC}/LeftAndMain.Ping.js`,
MemberImportForm: `${PATHS.LEGACY_SRC}/MemberImportForm.js`,
// For IE version 10 and below. These browsers doesn't handle large
// resource files so need to break browser detection and warning code into
// its own file
browserWarning: `${PATHS.SRC}/lib/browserWarning.js`,
},
output: {
path: PATHS.DIST,
filename: 'js/[name].js',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
resolve: resolveJS(ENV, PATHS),
externals: externalJS(ENV, PATHS),
module: moduleJS(ENV, PATHS),
plugins: [
...pluginJS(ENV, PATHS),
// Most vendor libs are loaded directly into the 'vendor' bundle (through require()
// calls in vendor.js). This ensures that any further require() calls in other
// bundles aren't duplicating libs.
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module => module.context && module.context.indexOf('/node_modules/') > -1,
}),
new CopyWebpackPlugin([
{
from: `${PATHS.MODULES}/moment/locale`,
to: `${PATHS.DIST}/moment-locales`
}
]),
],
watchOptions: {
poll: true
}
},
{
name: 'tinymce',
entry: {
TinyMCE_sslink: `${PATHS.LEGACY_SRC}/TinyMCE_sslink.js`,
'TinyMCE_sslink-external': `${PATHS.LEGACY_SRC}/TinyMCE_sslink-external.js`,
'TinyMCE_sslink-email': `${PATHS.LEGACY_SRC}/TinyMCE_sslink-email.js`,
},
output: {
path: PATHS.DIST,
filename: 'js/[name].js',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
resolve: resolveJS(ENV, PATHS),
externals: externalJS(ENV, PATHS),
module: moduleJS(ENV, PATHS),
plugins: [
...pluginJS(ENV, PATHS),
],
watchOptions: {
poll: true
}
},
{
name: 'i18n',
entry: {
'i18n': `${PATHS.SRC}/i18n.js`
},
output: {
path: PATHS.DIST,
filename: 'js/[name].js',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
resolve: resolveJS(ENV, PATHS),
externals: externalJS(ENV, PATHS),
module: moduleJS(ENV, PATHS),
plugins: pluginJS(ENV, PATHS),
},
{
name: 'css',
entry: {
bundle: `${PATHS.SRC}/styles/bundle.scss`,
editor: `${PATHS.SRC}/styles/editor.scss`,
GridField_print: `${PATHS.SRC}/styles/legacy/GridField_print.scss`,
// For IE version 10 and below. These browsers doesn't handle large
// resource files so need to break browser detection and warning code into
// its own file
'browser-warning': `${PATHS.SRC}/styles/browser-warning.scss`,
},
output: {
path: PATHS.DIST,
filename: 'styles/[name].css',
},
devtool: (ENV !== 'production') ? 'source-map' : '',
module: moduleCSS(ENV, PATHS),
plugins: [
...pluginCSS(ENV, PATHS),
new CopyWebpackPlugin([
{
context: `${PATHS.SRC}/images`,
from: 'chosen-sprite*.png',
to: `${PATHS.DIST}/images`
}
]),
],
},
];
// 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)
: module.exports = config;