Skip to content

Commit 20d0f3d

Browse files
committed
build(webpack): add Node.js target output
1 parent 6eb945c commit 20d0f3d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

build/bin.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ const fatalError = err => {
2424
// setup config for multiple outputs
2525
const webpackConfigList = []
2626

27+
// web target builds
2728
;[
2829
'.bundle',
2930
'.polyfill',
3031
''
3132
].forEach(outputType => {
32-
let config = {
33+
const config = {
3334
...webpackConfig,
3435
output: {
3536
...webpackOutput,
@@ -47,7 +48,7 @@ const webpackConfigList = []
4748
commonjs2: '@ecomplus/utils',
4849
root: 'ecomUtils'
4950
},
50-
'axios': 'axios'
51+
axios: 'axios'
5152
}]
5253
if (outputType === '') {
5354
// standalone lib output
@@ -58,6 +59,22 @@ const webpackConfigList = []
5859
webpackConfigList.push(config)
5960
})
6061

62+
// add Node.js output
63+
webpackConfigList.push({
64+
...webpackConfig,
65+
target: 'node',
66+
optimization: {
67+
minimize: false
68+
},
69+
output: {
70+
...webpackOutput,
71+
// CommonJS output instead of UMD
72+
libraryTarget: 'commonjs',
73+
filename: webpackOutput.filename.replace('.js', '.node.js')
74+
},
75+
externals: /^(@babel\/runtime|core-js|@ecomplus\/utils|axios)/i
76+
})
77+
6178
webpack(webpackConfigList, (err, stats) => {
6279
// console.log(stats)
6380
if (err) {
@@ -67,7 +84,7 @@ webpack(webpackConfigList, (err, stats) => {
6784
// check and handle webpack errors and warnings
6885
const info = stats.toJson()
6986
if (stats.hasErrors()) {
70-
let err = info.errors
87+
const err = info.errors
7188
fatalError(err)
7289
}
7390
if (stats.hasWarnings()) {

0 commit comments

Comments
 (0)