forked from facebookresearch/hiplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
125 lines (122 loc) · 3.83 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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
const fs = require('fs');
const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
const webpack = require("webpack");
const distPath = path.resolve(__dirname, 'dist');
class WhenDoneCopyToHiplotStaticDir {
constructor(env) {
this.env = env;
}
apply(compiler) {
compiler.hooks.afterEmit.tap('WhenDoneCopyToHiplotStaticDir', (
stats /* stats is passed as argument when done hook is tapped. */
) => {
var pyBuilt = path.resolve(__dirname, 'hiplot', 'static', 'built');
try {
fs.mkdirSync(pyBuilt, {recursive: true});
} catch (err) { /* `recursive` option is node >= 10.0. Otherwise will throw if the directory already exists */ }
const target = this.env && this.env.test ? "hiplot_test" : "hiplot";
fs.copyFileSync(path.resolve(distPath, `${target}.bundle.js`), path.resolve(pyBuilt, 'hiplot.bundle.js'));
});
}
}
module.exports = env => { return {
entry: {
'hiplot': `./src/hiplot.tsx`,
'hiplot_test': `./src/hiplot_test.tsx`,
},
output: {
path: distPath,
filename: '[name].bundle.js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.css', '.svg', '.scss'],
},
module: {
rules: [
{
test: /datatables\.net.*/,
loader: 'imports-loader?define=>false'
},
{
test: /\.(png|jp(e*)g|svg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 1000000, // Convert images < 1MB to base64 strings
name: 'images/[hash]-[name].[ext]'
}
}]
},
{
test: /\.s(a|c)ss$/,
exclude: /\.module.(s(a|c)ss)$/,
loader: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.css$/i,
use: [
"style-loader",
"@teamsupercell/typings-for-css-modules-loader",
{
loader: "css-loader",
options: {
modules: {
localIdentName: '[local]__[hash:base64:5]',
//localIdentName: '[local]',
}
}
},
]
},
{
test: /\.worker.ts?$/,
loader: 'worker-loader',
options: { inline: true, fallback: false }
},
{ parser: { amd: false } },
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
query: {
compilerOptions: {
declaration: false,
}
}
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: "pre",
test: /\.js$/,
loader: "source-map-loader"
},
],
},
stats: {
colors: true
},
plugins: [
new LicenseWebpackPlugin(),
new webpack.BannerPlugin(
" Copyright (c) Facebook, Inc. and its affiliates.\n\n\
This source code is licensed under the MIT license found in the\n\
LICENSE file in the root directory of this source tree."),
new WhenDoneCopyToHiplotStaticDir(env)
],
devtool: 'source-map'
}};