-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (46 loc) · 1.28 KB
/
index.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
const defaultLodashWebpackPluginOptions = {
shorthands: true,
cloning: true,
currying: true,
caching: true,
collections: true,
exotics: true,
guards: true,
metadata: true,
deburring: true,
unicode: true,
chaining: true,
memoizing: true,
coercions:true,
flattening: true,
paths:true,
placeholders: true
}
module.exports = (api, projectOptions) => {
let lodashPluginOptions = {}
if (projectOptions.pluginOptions && projectOptions.pluginOptions.lodash) {
lodashPluginOptions = projectOptions.pluginOptions.lodash
}
let { provide, webpackPluginOptions } = lodashPluginOptions
api.chainWebpack(webpackConfig => {
webpackConfig.module
.rule('js')
.use('babel-loader')
.loader('babel-loader')
.tap((options = {}) => {
options.plugins = [...(options.plugins || []), "lodash"]
return options
})
let lodashWebpackPluginOptions = Object.assign({}, webpackPluginOptions, defaultLodashWebpackPluginOptions)
webpackConfig
.plugin('lodash-webpack')
.use(require('lodash-webpack-plugin'), [lodashWebpackPluginOptions])
if (provide) {
const { ProvidePlugin } = require('webpack')
webpackConfig.plugin('provide')
.use(ProvidePlugin, [{
_: 'lodash'
}])
}
})
}