-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
104 lines (98 loc) · 2.43 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
const path = require('path')
const config = require('./config/index')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrors = require('friendly-errors-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isDev = process.env.NODE_ENV === 'development'
const isProd = process.env.NODE_ENV === 'production'
const isTest = process.env.NODE_ENV === 'testing'
const projectRoot = path.resolve(__dirname)
const assetsPath = (_path) => {
const assetsSubDirectory = isProd
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory
return path.posix.join(assetsSubDirectory, _path)
}
const conf = {
entry: {},
resolveLoader: {
modules: [
`${projectRoot}/node_modules`
]
},
resolve: {
extensions: ['.js', '.css'],
modules: [
`${projectRoot}/node_modules`
]
},
module: {
rules: [{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
}, {
test: /\.js$/,
loader: 'babel-loader'
}]
},
plugins: [
new webpack.DefinePlugin({
DEV: isDev,
PROD: isProd,
TEST: isTest
}),
new ProgressBarPlugin(),
new FriendlyErrors()
]
}
if (isDev) {
conf.mode = 'development'
conf.devtool = '#source-map'
conf.entry['rangeslider-js'] = `${projectRoot}/src/dev.js`
conf.module.rules.push({
test: /\.css$/,
use: ['style-loader', 'css-loader']
})
conf.plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
template: `dev.html`,
inject: true
})
)
} else {
conf.mode = 'production'
conf.entry = {
'rangeslider-js.min': `${projectRoot}/src/index.js`
}
conf.devtool = false
conf.output = {
path: config.build.assetsRoot,
filename: assetsPath('[name].js'),
chunkFilename: assetsPath('[id].js'),
library: 'rangesliderJs',
libraryExport: 'default',
libraryTarget: 'umd'
}
conf.plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'prod.html',
inject: false
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
)
if (config.build.bundleAnalyzerReport) {
conf.plugins.push(new BundleAnalyzerPlugin())
}
}
module.exports = conf