forked from visgl/deck.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
110 lines (99 loc) · 3.03 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
// const {getWebpackConfig} = require('ocular-dev-tools');
// module.exports = env => {
// const config = getWebpackConfig(env);
// // Unfortunately, ocular-dev-tool swallows logs...
// require('fs').writeFileSync('/tmp/ocular.log', JSON.stringify(config, null, 2));
// return config;
// };
/* eslint-disable import/no-extraneous-dependencies */
const {getWebpackConfig} = require('ocular-dev-tools');
module.exports = (env = {}) => {
let config = getWebpackConfig(env);
config.devtool = 'source-map';
// Enable SharedArrayBuffer in wasm
// config.devServer = config.devServer || {};
// config.devServer.headers = config.devServer.headers || {};
// config.devServer.headers['Cross-Origin-Embedder-Policy'] = 'require-corp';
// config.devServer.headers['Cross-Origin-Opener-Policy'] = 'same-origin';
config = addBabelSettings(config);
config.module.rules.push({
// Load worker tests
test: /\.worker\.js$/,
loader: 'worker-loader'
});
// config.module.rules.push({
// test: /\.wasm$/,
// loaders: ['base64-loader'],
// type: 'javascript/auto'
// });
// Look for babel plugin
config.module = config.module || {};
config.module.rules = config.module.rules || [];
const babelRule = config.module.rules.find(rule => rule.loader === 'babel-loader');
// If found, inject excludes in @babel/present-env to prevent transpile
if (babelRule && babelRule.options && babelRule.options.presets) {
babelRule.options.presets = babelRule.options.presets.map(preset => {
if (preset === '@babel/preset-env') {
return [
'@babel/preset-env',
{
exclude: [/transform-async-to-generator/, /transform-regenerator/]
}
];
}
return preset;
});
}
// Log regex
// eslint-disable-next-line
Object.defineProperty(RegExp.prototype, 'toJSON', {
value: RegExp.prototype.toString
});
// Uncomment to debug config
// console.warn(JSON.stringify(config, null, 2));
return [config];
};
function makeBabelRule() {
return {
// Compile source using babel
test: /(\.js|\.ts|\.tsx)$/,
loader: 'babel-loader',
include: [/modules\/.*\/src/, /modules\/.*\/test/],
exclude: [/node_modules/],
options: {
presets: [
'@babel/preset-react',
'@babel/preset-typescript',
[
'@babel/preset-env',
{
exclude: [/transform-async-to-generator/, /transform-regenerator/]
}
]
],
plugins: ['@babel/plugin-proposal-class-properties']
}
};
}
function addBabelSettings(config) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules.filter(r => r.loader !== 'babel-loader'),
makeBabelRule(),
// See https://github.com/apollographql/apollo-link-state/issues/302
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
}
]
},
resolve: {
...config.resolve,
extensions: ['.ts', '.tsx', '.js', '.json']
}
};
}