-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.parts.js
61 lines (49 loc) · 1.36 KB
/
webpack.parts.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
'use strict'
const path = require('path')
const { merge } = require('webpack-merge')
const development = require('./webpack.development.js')
const production = require('./webpack.production.js')
const AddVendorsPlugin = require('./plugins/add-vendors-plugin')
const paths = {
entry: path.resolve(__dirname, './dist/node/sdk.js'),
bundle: path.resolve(__dirname, 'dist/browser'),
}
const outputs = (base, env, mapping, overrides) => {
const collection = []
const library = 'sdk'
const windowLibrary = 'NeverminedSDK'
let environment = development
let ext = 'js'
if (env === 'production') {
environment = production
ext = `min.${ext}`
}
Object.entries(mapping).forEach(([target, extension]) => {
const filename = `[name].${library}.${extension}.${ext}`
const compiled = {
output: {
filename: filename,
library: target === 'window' ? windowLibrary : library,
libraryTarget: target,
path: paths.bundle,
},
plugins: [new AddVendorsPlugin(`${library}.${extension}.${ext}`)],
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
],
},
}
collection.push(merge(base, environment, compiled, overrides))
})
return collection
}
module.exports = {
outputs,
paths,
}