-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
146 lines (142 loc) · 3.58 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
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
139
140
141
142
143
144
145
146
const path = require('path')
const webpack = require('webpack')
const HtmlPlugin = require('html-webpack-plugin')
const merge = require('webpack-merge')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const PATHS = {
src: path.join(__dirname, 'src'),
example: path.join(__dirname, 'examples')
}
const EXTERNALS = {
react: {
root: 'React',
commonjs: 'react',
commonjs2: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom'
}
}
// `npm run build` to build dist or `npm start` to run dev server.
const TARGET = process.env.npm_lifecycle_event
var env = process.env.NODE_ENV || 'development'
var isDev = env === 'development'
// Common to both starting dev server and building for production.
const common = {
devtool: isDev ? 'eval' : false,
plugins: [
new webpack.DefinePlugin({
__SERVER__: isDev,
__DEVELOPMENT__: isDev,
__DEVTOOLS__: isDev,
'process.env': {
NODE_ENV: JSON.stringify(env),
BABEL_ENV: JSON.stringify(env)
}
}),
new webpack.NoEmitOnErrorsPlugin()
],
module: {
rules: [
{
test: /\.jsx?$/,
enforce: 'pre',
loader: 'eslint-loader',
include: [
PATHS.src,
PATHS.example
]
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
// Using source maps breaks urls in the CSS loader
// https://github.com/webpack/css-loader/issues/232
// This comment solves it, but breaks testing from a local network
// https://github.com/webpack/css-loader/issues/232#issuecomment-240449998
// 'css-loader?sourceMap',
'css-loader'
]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
}
]
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
}
]
}
}
// Default configuration. We will return this if webpack is called outside
// of npm.
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
entry: {
example: PATHS.example
},
devServer: {
contentBase: PATHS.example,
historyApiFallback: true,
hot: true,
compress: true,
inline: true,
stats: 'errors-only',
host: process.env.HOST || '0.0.0.0',
port: process.env.PORT || 8080
},
plugins: [
new HtmlPlugin({
template: path.join(PATHS.example, 'index-template.html'),
inject: 'body',
filename: 'index.html'
}),
new webpack.HotModuleReplacementPlugin()
]
})
} else if (TARGET === 'buildDist' || TARGET === 'build' || TARGET === 'analyze') {
let plugins = [
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 51200 // ~50kb
})
]
if (TARGET === 'analyze') {
plugins.push(new BundleAnalyzerPlugin())
}
module.exports = merge(common, {
entry: {
'vis-react-components.min': PATHS.src
},
output: {
library: 'vis-react-components',
path: path.join(__dirname, '/dist'),
libraryTarget: 'umd',
filename: '[name].js',
publicPath: '/'
},
plugins: plugins,
externals: EXTERNALS
})
}