forked from GeoTIFF/georaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (69 loc) · 1.94 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
const webpack = require('webpack');
const path = require('path');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const ThreadsPlugin = require('threads-plugin');
module.exports = (env, argv) => {
const {mode, target} = argv;
const targetFileNamePart = target === 'node' ? '' : '.browser';
const plugins = [
new ThreadsPlugin()
];
if (process.env.ANALYZE_GEORASTER_BUNDLE) {
plugins.push(new BundleAnalyzerPlugin({
analyzerHost: process.env.ANALYZER_HOST || "127.0.0.1"
}));
}
const externals = {};
const node = {};
// neutralize import 'threads/register' in geotiff.js
node['threads/register'] = 'empty';
// can't access fs on the web
if (target === 'web') node['fs'] = 'empty';
return {
entry: './src/index.js',
mode,
target: target,
output: {
path: path.resolve(__dirname, 'dist'),
filename: mode === 'production' ? `georaster${targetFileNamePart}.bundle.min.js` : `georaster${targetFileNamePart}.bundle.js`,
globalObject: 'typeof self !== \'undefined\' ? self : this',
library: 'GeoRaster',
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
},
{
test: /worker\.js$/,
use: {
loader: 'worker-loader',
options: {
inline: true,
fallback: false,
},
},
},
target === "web" && {
test: path.resolve(__dirname, 'node_modules/node-fetch/browser.js'),
use: 'null-loader'
},
target === "web" && {
test: path.resolve(__dirname, 'node_modules/tiny-worker/lib/index.js'),
use: 'null-loader'
}
].filter(Boolean),
},
node,
externals,
plugins
};
};