-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathplugins.js
More file actions
53 lines (44 loc) · 1.27 KB
/
plugins.js
File metadata and controls
53 lines (44 loc) · 1.27 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
function css(options) {
if (options.target !== 'client') return false
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
return new MiniCssExtractPlugin({
filename: `${options.target}.css`,
chunkFilename: `[chunkhash].${options.target}.css`,
})
}
function hmr(options) {
if (options.environment !== 'development') return false
const { HotModuleReplacementPlugin } = require('webpack')
return new HotModuleReplacementPlugin()
}
function copy(options) {
if (!options.disk) return false
const CopyPlugin = require('copy-webpack-plugin')
return new CopyPlugin({
patterns: [
{ from: 'public', to: `../${options.buildFolder}` }
],
})
}
function nodemon(options) {
if (options.environment !== 'development') return false
if (options.target !== 'server') return false
const NodemonPlugin = require('nodemon-webpack-plugin')
const dotenv = options.name ? `.env.${options.name}` : '.env'
return new NodemonPlugin({
ext: '*',
watch: [dotenv, './server.js'],
script: './.development/server.js',
nodeArgs: ['--enable-source-maps'],
quiet: true,
})
}
function plugins(options) {
return [
css(options),
hmr(options),
copy(options),
nodemon(options),
].filter(Boolean)
}
module.exports = plugins