forked from livingdocsIO/editable.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
96 lines (92 loc) · 2.07 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
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 webpack = require('webpack')
const dev = process.env.WEBPACK_DEV === 'true'
const production = !dev
const dist = process.env.BUILD_DIST === 'true'
const docs = process.env.BUILD_DOCS === 'true'
const test = process.env.BUILD_TEST === 'true'
module.exports = {
mode: dev ? 'development' : 'production',
devtool: 'source-map',
target: 'web',
entry: {
...(dist ? {
'dist/editable': './src/core.js'
} : {}),
...(docs ? {
'examples/dist/bundle': './examples/index.js',
'examples/dist/styles': './examples/index.css'
} : {})
},
output: {
library: dist ? 'Editable' : undefined,
libraryTarget: 'umd',
libraryExport: 'Editable',
path: __dirname,
filename: '[name].js'
},
externals: dist ? {
jquery: 'jQuery'
} : {},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-runtime',
...(test ? ['babel-plugin-istanbul'] : [])
],
presets: [
'@babel/preset-env',
...(!production || docs ? ['@babel/preset-react'] : [])
]
}
}
]
},
...(docs ? [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /\.(png|jpe?g|svg|gif|eot|ttf|woff2?)/,
loader: 'url-loader'
}
] : [])
]
},
optimization: {
nodeEnv: production ? 'production' : false
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
],
...(test ? {
resolve: {
alias: {
sinon: 'sinon/pkg/sinon.js',
chai: '@esm-bundle/chai'
}
}
} : {}),
...(dev ? {
devServer: {
static: {
directory: './'
},
port: 9050,
historyApiFallback: true,
liveReload: true,
hot: true,
open: {
target: '/examples'
}
}
} : {})
}