UNPKG

919 BJavaScriptView Raw
1exports.name = 'builtin:config-electron'
2
3exports.apply = (api, { bundleDependencies } = {}) => {
4 api.hook('onCreateWebpackConfig', config => {
5 if (api.config.target !== 'electron') return
6
7 // Force public URL
8 config.output.publicPath('./')
9 config.plugin('constants').tap(([options]) => [
10 Object.assign(options, {
11 __PUBLIC_URL__: JSON.stringify('./')
12 })
13 ])
14
15 config.target('electron-renderer')
16
17 const externals = config.get('externals') || []
18 externals.push((context, request, callback) => {
19 const deps = Object.keys(api.pkg.data.dependencies || {})
20 const depsToExclude = bundleDependencies ? [] : deps
21 const shouldExclude = depsToExclude.some(dep => {
22 return request.includes(`/node_modules/${dep}/`)
23 })
24 if (shouldExclude) {
25 callback(null, `commonjs ${request}`)
26 } else {
27 callback()
28 }
29 })
30 })
31}