/
webpack.config.local.js
115 lines (101 loc) · 3.47 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
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
// 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.
// avoid destructuring for older Node version support
const resolve = require('path').resolve;
const webpack = require('webpack');
const LIB_DIR = resolve(__dirname, '../..');
const SRC_DIR = resolve(LIB_DIR, 'modules');
const ALIASES = require('../../aliases')('src');
// Support for hot reloading changes to the deck.gl library:
function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR) {
return {
// TODO - Uncomment when all examples use webpack 4 for faster bundling
// mode: 'development',
// suppress warnings about bundle size
devServer: {
stats: {
warnings: false
}
},
devtool: 'source-map',
resolve: {
alias: Object.assign({}, ALIASES, {
// Use luma.gl specified by root package.json
'luma.gl': resolve(LIB_DIR, './node_modules/luma.gl'),
// Important: ensure shared dependencies come from the main node_modules dir
// Versions will be controlled by the deck.gl top level package.json
'math.gl': resolve(LIB_DIR, './node_modules/math.gl'),
'viewport-mercator-project': resolve(LIB_DIR, './node_modules/viewport-mercator-project'),
seer: resolve(LIB_DIR, './node_modules/seer'),
react: resolve(LIB_DIR, './node_modules/react')
})
},
module: {
rules: [
{
// Unfortunately, webpack doesn't import library sourcemaps on its own...
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre'
}
]
},
// Optional: Enables reading mapbox token from environment variable
plugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken'])]
};
}
const BUBLE_CONFIG = {
module: {
rules: [
{
// Compile source using buble
test: /\.js$/,
loader: 'buble-loader',
include: [SRC_DIR],
options: {
objectAssign: 'Object.assign',
transforms: {
dangerousForOf: true,
modules: false
}
}
}
]
}
};
function addLocalDevSettings(config, exampleDir) {
const LOCAL_DEV_CONFIG = makeLocalDevConfig(exampleDir);
config = Object.assign({}, LOCAL_DEV_CONFIG, config);
config.resolve = config.resolve || {};
config.resolve.alias = config.resolve.alias || {};
Object.assign(config.resolve.alias, LOCAL_DEV_CONFIG.resolve.alias);
config.module = config.module || {};
Object.assign(config.module, {
rules: (config.module.rules || []).concat(LOCAL_DEV_CONFIG.module.rules)
});
return config;
}
function addBubleSettings(config) {
config.module = config.module || {};
Object.assign(config.module, {
rules: (config.module.rules || []).concat(BUBLE_CONFIG.module.rules)
});
return config;
}
module.exports = (config, exampleDir) => env => {
// npm run start-local now transpiles the lib
if (env && env.local) {
config = addLocalDevSettings(config, exampleDir);
config = addBubleSettings(config);
}
// npm run start-es6 does not transpile the lib
if (env && env.es6) {
config = addLocalDevSettings(config, exampleDir);
}
// console.warn(JSON.stringify(config, null, 2)); // uncomment to debug config
return config;
};