-
Notifications
You must be signed in to change notification settings - Fork 28
/
webpack.config.js
98 lines (88 loc) · 2.63 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
const envisage = require("envisage");
const path = require('path');
const config = (env, argv) => {
const {mode, target} = argv;
// const filename = `geoblaze.${target}${mode === 'production' ? '.min' : ''}.js`;
const results = {
mode,
devtool: 'source-map',
// entry: './src/index.js',
output: {
library: 'geoblaze',
path: path.resolve(__dirname, 'dist'),
// filename,
globalObject: `(typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : typeof global !== 'undefined' ? global : typeof this !== 'undefined' ? this : undefined)`,
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
modules: [path.join(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.json'],
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
include: /src/,
},
{
test: /\.js/,
loader: 'babel-loader',
exclude: modulePath => {
// need to compile these
if (["/node_modules/mpoly/mpoly.js", "/node_modules/geowarp/geowarp.js"].some(fp => modulePath.endsWith(fp))) {
return false;
}
return /node_modules/.test(modulePath) &&
!/node_modules\/webpack-dev-server/.test(modulePath) &&
!/node_modules\/map-obj/.test(modulePath)
},
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
ie: 11
}
}
]
],
plugins: [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
]
}
},
target === "web" && {
test: path.resolve(__dirname, 'node_modules/node-fetch/browser.js'),
use: 'null-loader'
}
].filter(Boolean),
},
stats: {
colors: true,
chunks: true,
},
plugins: [],
node: {}
};
if (target === "web") {
results.node['fs'] = 'empty';
}
if (mode === "development") {
results.devServer = {
publicPath: '/',
historyApiFallback: true,
};
}
// inject environmental variables
envisage.assign({ prefix: "GEOBLAZE_WEBPACK", target: results });
if (!results.entry) throw new Error("no GEOBLAZE_WEBPACK_ENTRY");
if (!results.output.filename) throw new Error("no GEOBLAZE_WEBPACK_OUTPUT_FILENAME");
return results;
};
module.exports = config;