forked from contentful/contentful.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
66 lines (56 loc) · 1.41 KB
/
webpack.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
const path = require('path')
const copy = require('fast-copy')
const webpack = require('webpack')
const __VERSION__ = require('./package.json').version
const PROD = process.env.NODE_ENV === 'production'
const baseFileName = 'contentful'
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__VERSION__: JSON.stringify(__VERSION__),
}),
]
if (PROD) {
plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
})
)
}
const defaultTsLoader = {
test: /\.ts?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {},
}
const baseBundleConfig = {
mode: PROD ? 'production' : 'development',
context: path.join(__dirname, 'lib'),
entry: [`./index.ts`],
resolve: {
extensions: ['.ts', '.js'],
},
output: {
path: path.join(__dirname, 'dist'),
},
module: {
rules: [defaultTsLoader],
},
plugins,
}
const nodeBundle = copy(baseBundleConfig)
nodeBundle.output.library = {
type: 'umd2',
name: 'contentful',
}
nodeBundle.target = 'node'
nodeBundle.output.filename = `${baseFileName}.node${PROD ? '.min' : ''}.js`
const browserBundle = copy(baseBundleConfig)
browserBundle.output.library = {
type: 'umd2',
name: 'contentful',
}
browserBundle.target = 'browserslist'
browserBundle.output.filename = `${baseFileName}.browser${PROD ? '.min' : ''}.js`
module.exports = [nodeBundle, browserBundle]