forked from visgl/react-map-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.local.js
75 lines (67 loc) · 2.02 KB
/
webpack.config.local.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
// This file contains webpack configuration settings that allow
// examples to be built against the deck.gl source code in this repo instead
// of building against their installed version of deck.gl.
//
// This enables using the examples to debug the main deck.gl library source
// without publishing or npm linking, with conveniences such hot reloading etc.
const {resolve} = require('path');
const webpack = require('webpack');
const LIB_DIR = resolve(__dirname, '..');
const SRC_DIR = resolve(LIB_DIR, './src');
const BABEL_CONFIG = {
presets: ['@babel/env', '@babel/react', '@babel/flow'],
plugins: ['@babel/proposal-class-properties']
};
// Support for hot reloading changes
const LOCAL_DEVELOPMENT_CONFIG = {
// suppress warnings about bundle size
devServer: {
stats: {
warnings: false
}
},
devtool: 'source-map',
resolve: {
alias: {
// Imports the react-map-gl library from the src directory in this repo
'react-map-gl': SRC_DIR,
'../utils/mapboxgl': resolve(LIB_DIR, './node_modules/mapbox-gl/dist/mapbox-gl-dev.js'),
react: resolve(LIB_DIR, './node_modules/react')
}
},
module: {
rules: [
{
// Compile ES2015 using babel
test: /\.js$/,
include: [SRC_DIR],
use: [
{
loader: 'babel-loader',
options: BABEL_CONFIG
}
]
}
]
},
// Optional: Enables reading mapbox token from environment variable
plugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken'])]
};
function addLocalDevSettings(config) {
config.resolve = config.resolve || {};
config.resolve.alias = Object.assign(
{},
config.resolve.alias,
LOCAL_DEVELOPMENT_CONFIG.resolve.alias
);
config.module.rules = config.module.rules.concat(LOCAL_DEVELOPMENT_CONFIG.module.rules);
config.devtool = LOCAL_DEVELOPMENT_CONFIG.devtool;
return config;
}
module.exports = baseConfig => env => {
const config = baseConfig;
if (env && env.local) {
addLocalDevSettings(config);
}
return config;
};