forked from sidx1024/deck.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
125 lines (100 loc) · 2.89 KB
/
webpack.config.js
File metadata and controls
125 lines (100 loc) · 2.89 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
118
119
120
121
122
123
124
125
const {resolve, join} = require('path');
const webpack = require('webpack');
const rootDir = join(__dirname, '..');
const libSources = join(rootDir, 'src');
// Otherwise modules imported from outside this directory does not compile
// Seems to be a Babel bug
// https://github.com/babel/babel-loader/issues/149#issuecomment-191991686
const BABEL_CONFIG = {
presets: [
'es2015',
'stage-2',
'react'
].map(name => require.resolve(`babel-preset-${name}`)),
plugins: [
'transform-decorators-legacy'
].map(name => require.resolve(`babel-plugin-${name}`))
};
const COMMON_CONFIG = {
entry: ['./src/main'],
module: {
rules: [
{
// Compile ES2015 using bable
test: /\.js$/,
loader: 'babel-loader',
options: BABEL_CONFIG,
include: [resolve('..'), libSources],
exclude: [/node_modules/]
}, {
test: /\.scss$/,
loaders: ['style-loader', 'css-loader', 'sass-loader', 'autoprefixer-loader']
}, {
test: /\.(eot|svg|ttf|woff|woff2|gif|jpe?g|png)$/,
loader: 'url-loader'
}
],
// Uglify seems to be incompatible with mapbox
// https://github.com/mapbox/mapbox-gl-js/issues/4359#issuecomment-288001933
noParse: /(mapbox-gl)\.js$/
},
resolve: {
alias: {
// For importing modules that are not exported at root
'deck.gl/dist': libSources,
'deck.gl': libSources,
'luma.gl': resolve('.', './node_modules/luma.gl'),
react: resolve('.', './node_modules/react'),
// // used by Mapbox
// webworkify: 'webworkify-webpack-dropin',
// From mapbox-gl-js README. Required for non-browserify bundlers (e.g. webpack):
'mapbox-gl$': resolve('./node_modules/mapbox-gl/dist/mapbox-gl.js'),
'd3-scale': resolve('.', './node_modules/d3-scale'),
rbush: resolve('.', './node_modules/rbush')
}
},
node: {
fs: 'empty'
},
plugins: [
new webpack.DefinePlugin({
MapboxAccessToken: `"${process.env.MapboxAccessToken}"` // eslint-disable-line
})
]
};
const addDevConfig = config => {
config.module.rules.push({
// Unfortunately, webpack doesn't import library sourcemaps on its own...
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre'
});
return Object.assign(config, {
devtool: 'source-maps',
plugins: config.plugins.concat([
// new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
])
});
};
const addProdConfig = config => {
return Object.assign(config, {
output: {
path: resolve(__dirname, './dist'),
filename: 'bundle.js'
}
});
};
module.exports = env => {
env = env || {};
let config = COMMON_CONFIG;
if (env.local) {
config = addDevConfig(config);
}
if (env.prod) {
config = addProdConfig(config);
}
// Enable to debug config
// console.warn(JSON.stringify(config, null, 2));
return config;
};