forked from contentful/contentful.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
96 lines (84 loc) · 2.28 KB
/
webpack.config.js
File metadata and controls
96 lines (84 loc) · 2.28 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
const path = require('path')
const webpack = require('webpack')
const copy = require('fast-copy')
const PROD = process.env.NODE_ENV === 'production'
const plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
if (PROD) {
plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
)
}
const baseFileName = 'contentful'
const baseBundleConfig = {
mode: PROD ? 'production' : 'development',
context: path.join(__dirname, 'lib'),
entry: [`./${baseFileName}.js`],
output: {
path: path.join(__dirname, 'dist'),
libraryTarget: 'umd',
library: 'contentful'
},
module: {
rules: []
},
devtool: PROD ? false : 'source-map',
plugins,
node: {
os: 'empty'
},
// Show minimal information, but all errors and warnings
// Except for log generation which have to contain all information
stats: process.env.WEBPACK_MODE === 'log' ? 'verbose' : 'normal'
}
const defaultBabelLoader = {
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {}
}
// Browsers with native async await calls
const browserBundle = copy(baseBundleConfig)
browserBundle.module.rules = [
Object.assign({}, defaultBabelLoader, {
options: Object.assign({}, defaultBabelLoader.options, {
envName: 'browser'
})
})
]
browserBundle.output.filename = `${baseFileName}.browser${PROD ? '.min' : ''}.js`
// Legacy browsers like IE11, with bundled regenerator-runtime
const legacyBundle = copy(baseBundleConfig)
legacyBundle.module.rules = [
Object.assign({}, defaultBabelLoader, {
options: Object.assign({}, defaultBabelLoader.options, {
envName: 'legacy'
})
})
]
legacyBundle.output.filename = `${baseFileName}.legacy${PROD ? '.min' : ''}.js`
// Node - bundled umd file
const nodeBundle = copy(baseBundleConfig)
nodeBundle.module.rules = [
Object.assign({}, defaultBabelLoader, {
options: Object.assign({}, defaultBabelLoader.options, {
envName: 'node'
})
})
]
nodeBundle.target = 'node'
nodeBundle.output.libraryTarget = 'commonjs2'
nodeBundle.output.filename = `${baseFileName}.node${PROD ? '.min' : ''}.js`
delete nodeBundle.node
module.exports = [
browserBundle,
legacyBundle,
nodeBundle
]