forked from sidx1024/deck.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.local.js
More file actions
117 lines (105 loc) · 3.65 KB
/
webpack.config.local.js
File metadata and controls
117 lines (105 loc) · 3.65 KB
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
116
117
// 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, './src');
// Support for hot reloading changes to the deck.gl library:
function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR) {
return {
// suppress warnings about bundle size
devServer: {
stats: {
warnings: false
}
},
devtool: 'source-map',
resolve: {
alias: {
// For importing modules that are not exported at root
'deck.gl/dist': SRC_DIR,
// Imports the deck.gl library from the src directory in this repo
'deck.gl': SRC_DIR,
// Imports the deck.gl library from the src directory in this repo
'deck.gl-layers': resolve(SRC_DIR, './experimental-layers/src'),
// 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);
// console.warn(JSON.stringify(config, null, 2));
}
// npm run start-es6 does not transpile the lib
if (env && env.es6) {
config = addLocalDevSettings(config, exampleDir);
// console.warn(JSON.stringify(config, null, 2));
}
return config;
};