/
webpack.config.js
64 lines (61 loc) · 2.31 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
const path = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const pkg = require('./package.json');
const sourceDir = path.resolve(__dirname, 'src');
const buildDir = path.resolve(__dirname, 'dist');
const shimPath = path.resolve(sourceDir, 'shim.js');
function shim(regExp, path) {
return new webpack.NormalModuleReplacementPlugin(regExp, path || shimPath);
}
module.exports = {
stats: { warnings: false },
mode: process.env.NODE_ENV || 'development',
entry: path.resolve(sourceDir, 'index.js'),
output: {
filename: `${pkg.displayname}.min.js`,
path: buildDir
},
plugins: [
// replace CSS
shim(/@jupyterlab\/.*\.css/, path.resolve(sourceDir, `${pkg.displayname}.css`)),
// shim unused packages – source: https://github.com/minrk/thebelab
shim(/moment/),
shim(/codemirror\/keymap\/vim/),
shim(/codemirror\/addon\/search/),
shim(/@phosphor\/coreutils\/lib\/random/),
shim(/@phosphor\/widgets\/lib\/(commandpalette|box|dock|grid|menu|scroll|split|stacked|tab).*/),
shim(/@phosphor\/(dragdrop|commands).*/),
shim(/@jupyterlab\/apputils/),
shim(/@jupyterlab\/codeeditor\/lib\/jsoneditor/),
shim(/@jupyterlab\/coreutils\/lib\/(time|settingregistry|.*menu.*)/),
shim(/@jupyterlab\/services\/lib\/(session|contents|terminal)\/.*/),
new UglifyJSPlugin({ cache: true, parallel: true, sourceMap: false }),
new webpack.BannerPlugin(`${pkg.name}\n${pkg.description}\n\n@author ${pkg.author}\n@version ${pkg.version}\n@license ${pkg.license}`)
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
query: { presets: ['env'] }
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
options: {
singleton: true,
insertAt: 'top',
attrs: { 'data-added-by': pkg.displayname }
}
},
{
loader: 'css-loader'
}
]
}
]
}
}