forked from silverstripe/silverstripe-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
196 lines (191 loc) · 6 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
// const SprityWebpackPlugin = require('sprity-webpack-plugin');
const PATHS = {
MODULES: './node_modules',
ADMIN_IMAGES: './client/dist/images',
ADMIN_CSS_SRC: './client/src/styles',
ADMIN_CSS_DIST: './client/dist/styles',
ADMIN_THIRDPARTY: './thirdparty',
ADMIN_JS_SRC: './client/src',
ADMIN_JS_DIST: './client/dist/js',
};
// Used for autoprefixing css properties (same as Bootstrap Aplha.2 defaults)
const SUPPORTED_BROWSERS = [
'Chrome >= 35',
'Firefox >= 31',
'Edge >= 12',
'Explorer >= 9',
'iOS >= 8',
'Safari >= 8',
'Android 2.3',
'Android >= 4',
'Opera >= 12',
];
const config = [
{
name: 'js',
entry: {
vendor: `${PATHS.ADMIN_JS_SRC}/bundles/vendor.js`,
bundle: `${PATHS.ADMIN_JS_SRC}/bundles/bundle.js`,
'LeftAndMain.Ping': `${PATHS.ADMIN_JS_SRC}/legacy/LeftAndMain.Ping.js`,
leaktools: `${PATHS.ADMIN_JS_SRC}/legacy/leaktools.js`,
MemberImportForm: `${PATHS.ADMIN_JS_SRC}/legacy/MemberImportForm.js`,
TinyMCE_sslink: `${PATHS.ADMIN_JS_SRC}/legacy/TinyMCE_sslink.js`,
},
resolve: {
root: [__dirname, path.resolve(__dirname, PATHS.ADMIN_JS_SRC)],
modulesDirectories: [PATHS.MODULES],
},
output: {
path: 'client/dist',
filename: 'js/[name].js',
},
// lib.js provies these globals and more. These references allow the framework bundle
// to access them.
externals: {
'apollo-client': 'ApolloClient',
'bootstrap-collapse': 'BootstrapCollapse',
'components/Breadcrumb/Breadcrumb': 'Breadcrumb',
'state/breadcrumbs/BreadcrumbsActions': 'BreadcrumbsActions',
'state/schema/SchemaActions': 'SchemaActions',
'components/FieldHolder/FieldHolder': 'FieldHolder',
'components/FormAction/FormAction': 'FormAction',
'components/FormBuilder/FormBuilder': 'FormBuilder',
'components/FormBuilderModal/FormBuilderModal': 'FormBuilderModal',
'components/GridField/GridField': 'GridField',
'components/Toolbar/Toolbar': 'Toolbar',
'containers/FormBuilderLoader/FormBuilderLoader': 'FormBuilderLoader',
'deep-freeze-strict': 'DeepFreezeStrict',
'graphql-fragments': 'GraphQLFragments',
'graphql-tag': 'GraphQLTag',
i18n: 'i18n',
jquery: 'jQuery',
'lib/Backend': 'Backend',
'lib/ReducerRegister': 'ReducerRegister',
'lib/ReactRouteRegister': 'ReactRouteRegister',
'lib/SilverStripeComponent': 'SilverStripeComponent',
'page.js': 'Page',
'react-addons-test-utils': 'ReactAddonsTestUtils',
'react-dom': 'ReactDom',
tether: 'Tether',
'react-apollo': 'ReactApollo',
'react-bootstrap-ss': 'ReactBootstrap',
'react-redux': 'ReactRedux',
'react-router-redux': 'ReactRouterRedux',
'react-router': 'ReactRouter',
'react-addons-css-transition-group': 'ReactAddonsCssTransitionGroup',
react: 'React',
'redux-form': 'ReduxForm',
'redux-thunk': 'ReduxThunk',
redux: 'Redux',
config: 'Config',
'lib/Router': 'Router',
qs: 'qs',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|thirdparty)/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
plugins: ['transform-object-assign', 'transform-object-rest-spread'],
comments: false,
},
},
{
test: '/i18n.js/',
loader: 'script-loader',
},
],
},
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
}),
new webpack.DefinePlugin({
'process.env': {
// Builds React in production mode, avoiding console warnings
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: false,
warnings: false,
},
output: {
beautify: false,
semicolons: false,
comments: false,
max_line_len: 200,
},
}),
// 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: Infinity,
}),
],
},
{
name: 'css',
entry: {
bundle: `${PATHS.ADMIN_CSS_SRC}/bundle.scss`,
editor: `${PATHS.ADMIN_CSS_SRC}/editor.scss`,
GridField_print: `${PATHS.ADMIN_CSS_SRC}/legacy/GridField_print.scss`,
},
output: {
path: 'client/dist/styles',
filename: '[name].css',
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract([
'css?sourceMap&minimize&-core&discardComments',
'postcss?sourceMap',
'resolve-url',
'sass?sourceMap',
]),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract([
'css?sourceMap&minimize&-core&discardComments',
'postcss?sourceMap',
]),
},
{
test: /\.(png|gif|jpg|svg)$/,
exclude: /fonts\/([\w_-]+)\.svg$/,
loader: 'url?limit=10000&name=../images/[name].[ext]',
},
{
test: /fonts\/([\w_-]+)\.(woff|eot|ttf|svg)$/,
loader: 'file?name=../fonts/[name].[ext]',
},
],
},
postcss: [
autoprefixer({ browsers: SUPPORTED_BROWSERS }),
],
plugins: [
new ExtractTextPlugin('[name].css', { allChunks: true }),
],
},
];
// Use WEBPACK_CHILD=js or WEBPACK_CHILD=css env var to run a single config
if (process.env.WEBPACK_CHILD) {
module.exports = config.filter((entry) => entry.name === process.env.WEBPACK_CHILD)[0];
} else {
module.exports = config;
}