-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
189 lines (175 loc) · 6.72 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
/**
* Created by bvanlew on 11/05/2017.
*/
// refer to https://webpack.js.org/concepts/
process.traceDeprecation = true;
const path = require('path');
const rf = require('rimraf');
const WebpackShellPlugin = require('webpack-shell-plugin-next');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const isProd = (process.env.NODE_ENV === 'production');
const isDev = !isProd;
// copy the outputs to the test directories after the build
console.log('clean old dist directory');
rf.sync('./dist');
const webPackShell = new WebpackShellPlugin({
onBuildExit:{
scripts: [
'echo-cli "Copy rescatter files to webdriver test"...',
'copyfiles -V -f ../ReScatter/dist/rescatter.js test/browser_tests/html/',
'copyfiles -V -f ../BrainScope/app/static/js/vendor/webix.js test/browser_tests/html/',
'echo-cli "Copy rescatter files to BrainScope website framework"...',
'copyfiles -V -f ../ReScatter/dist/rescatter_dark.css ../BrainScope/app/static/css',
'copyfiles -V -f ../ReScatter/dist/rescatter.js ../BrainScope/app/static/js/framework',
'copyfiles -V -f ../ReScatter/dist/fonts/*.* ../BrainScope/app/static/css',
'echo-cli "Copy rescatter files to example framework"...',
'copyfiles -V -f ../ReScatter/src/rescatter_layouts.js ../ReScatter/example/framework',
'copyfiles -V -f ../ReScatter/dist/rescatter_dark.css ../ReScatter/example/framework',
'copyfiles -V -f ../ReScatter/dist/rescatter_light.css ../ReScatter/example/framework',
'copyfiles -V -f ../ReScatter/dist/rescatter.js ../ReScatter/example/framework',
'copyfiles -V -f ../ReScatter/dist/rescatter.js.map ../ReScatter/example/framework',
'echo-cli "Copy rescatter files to tools framework"...',
'copyfiles -V -f ../ReScatter/dist/rescatter.js ../ReScatter/tools/framework',
'copyfiles -V -f ../ReScatter/dist/rescatter.js.map ../ReScatter/tools/framework',
'copyfiles -V -f ../ReScatter/dist/fonts/*.* ../ReScatter/example/framework/fonts'
],
blocking: true,
parallel: false
}
});
let webPackConfig = {
//define the base path as parent
context: path.resolve(__dirname, './'), // eslint-disable-line no-undef
// entry: Where to start creating the dependency graph for the bundle
// allows multiple entry points to handle separate bundles
entry: {
'rescatter': './src/index.js',
'rescatter_light': './src/themes/light/rescatter_light.less',
'rescatter_dark': './src/themes/dark/rescatter_dark.less'
},
// output: Where to place the output bundle
output: {
// path relative to this file
path: path.resolve(__dirname, 'dist'), // eslint-disable-line no-undef
filename: '[name].js', // output name from entry name (key)
library: 'ReScatter',
libraryTarget: 'umd'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
// limit support to these browser versions and above
presets: [
[
'@babel/preset-env',
{
'targets': {
'chrome': '58',
'opera': '45',
'firefox': '52',
'safari': '10.1.2'
}
}
]
],
plugins: [
// '@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties' // for static methods
]
}
}
},
{
test: /\.(png|jpg)$/,
use: {
loader: 'url-loader?limit=8192' //inline base64 images up to 8k
}
},
{
test: /\.(frag|vert)$/,
use: {
loader: 'webpack-glsl-loader'
}
},
{
test: /\.less$/,
use: [
{
// emit CSS as separate file
loader: 'file-loader',
options: {
name: '[name].css',
outputPath: '.' //relative to main output above
}
},
{
// extract the CSS from the bundle
loader: 'extract-loader'
},
{
loader:'css-loader', options: {sourceMap: isDev}
},
{
// Resolve the file relative imports in less
// Remove any query URL component (found in webix material less)
// since we are loading from a local directory
loader:'resolve-url-loader'
},
{
loader: 'less-loader', options: {sourceMap: isDev}
}
]
},
{
test: /\.(woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
}
}
]
}
]
},
node: {
fs: 'empty'
},
// Add plugins for Uglify or creation of a dist/index.html with all
//plugins: [new webpack.HotModuleReplacementPlugin(), new HtmlWebpackPlugin()],
plugins: [
webPackShell,
],
externals: {
webix: 'webix', //webix is external and available at the global variable webix
'pixi.js': 'pixi.js'
},
resolve: {
alias: {
'jquery-resizable-dom': 'jquery-resizable-dom/dist/jquery-resizable.min.js'
}
}
};
if (isProd) {
webPackConfig.plugins.push(
new UglifyJsPlugin({
test: [
/\.js$/i
],
sourceMap: true,
uglifyOptions: {
ecma: 8,
compress: { warnings: false, unused: false },
output: { comments: false },
},
})
);
}
module.exports = webPackConfig;