forked from CartoDB/cartodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.config.js
138 lines (129 loc) · 3.86 KB
/
webpack.dev.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
const webpack = require('webpack');
const {resolve} = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const PACKAGE = require('./package.json');
const version = PACKAGE.version;
const stats = (env) => {
return env && env.stats;
};
const isVendor = (module, count) => {
const userRequest = module.userRequest;
return userRequest && userRequest.indexOf('node_modules') >= 0;
};
const entryPoints = {
builder_embed: ['whatwg-fetch', './lib/assets/javascripts/cartodb3/public_editor.js'],
dataset: './lib/assets/javascripts/cartodb3/dataset.js',
builder: './lib/assets/javascripts/cartodb3/editor.js'
};
module.exports = env => {
return {
entry: entryPoints,
output: {
filename: `${version}/javascripts/[name].js`,
path: resolve(__dirname, 'public/assets')
},
resolve: {
symlinks: false,
modules: [
resolve(__dirname, 'node_modules'),
resolve(__dirname, 'lib/assets/node_modules')
]
},
devtool: 'source-map',
plugins: [
stats(env) ? new BundleAnalyzerPlugin({
analyzerMode: 'static'
}) : undefined
].concat(
// For each entry point, we generate the vendor file
Object.keys(entryPoints)
.map(entry => new webpack.optimize.CommonsChunkPlugin({
name: `${entry}_vendor`,
chunks: [entry],
minChunks: isVendor
}))
)
.concat([
// Extract common chuncks from the 3 vendor files
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
chunks: Object.keys(entryPoints).map(n => `${n}_vendor`),
minChunks: (module, count) => {
return count >= Object.keys(entryPoints).length && isVendor(module);
}
}),
// Extract common chuncks from the 3 entry points
new webpack.optimize.CommonsChunkPlugin({
children: true,
minChunks: Object.keys(entryPoints).length
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new webpack.DefinePlugin({
__IN_DEV__: JSON.stringify(true),
__ENV__: JSON.stringify('dev')
})
])
.filter(p => !!p), // undefined is not a valid plugin, so filter undefined values here
module: {
rules: [
{
test: /\.js$/,
loader: 'shim-loader',
include: [
resolve(__dirname, 'node_modules/cartodb.js')
],
options: {
shim: {
'wax.cartodb.js': {
exports: 'wax'
},
'html-css-sanitizer': {
exports: 'html'
},
'lzma': {
exports: 'LZMA'
}
}
}
},
{
test: /\.tpl$/,
use: 'tpl-loader',
include: [
resolve(__dirname, 'lib/assets/javascripts/cartodb3'),
resolve(__dirname, 'lib/assets/javascripts/deep-insights'),
resolve(__dirname, 'node_modules/cartodb.js')
]
},
{
test: /\.mustache$/,
use: 'raw-loader',
include: [
resolve(__dirname, 'lib/assets/javascripts/cartodb3'),
resolve(__dirname, 'lib/assets/javascripts/deep-insights'),
resolve(__dirname, 'node_modules/cartodb.js')
]
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [
resolve(__dirname, 'node_modules/tangram-cartocss'),
resolve(__dirname, 'node_modules/tangram.cartodb')
],
options: {
presets: ['es2015']
}
}
]
},
node: {
fs: 'empty' // This fixes the error Module not found: Error: Can't resolve 'fs'
},
stats: 'normal'
};
};