Skip to content

Commit

Permalink
build(webpack): add Node.js target output
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 28, 2019
1 parent 6eb945c commit 20d0f3d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions build/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ const fatalError = err => {
// setup config for multiple outputs
const webpackConfigList = []

// web target builds
;[
'.bundle',
'.polyfill',
''
].forEach(outputType => {
let config = {
const config = {
...webpackConfig,
output: {
...webpackOutput,
Expand All @@ -47,7 +48,7 @@ const webpackConfigList = []
commonjs2: '@ecomplus/utils',
root: 'ecomUtils'
},
'axios': 'axios'
axios: 'axios'
}]
if (outputType === '') {
// standalone lib output
Expand All @@ -58,6 +59,22 @@ const webpackConfigList = []
webpackConfigList.push(config)
})

// add Node.js output
webpackConfigList.push({
...webpackConfig,
target: 'node',
optimization: {
minimize: false
},
output: {
...webpackOutput,
// CommonJS output instead of UMD
libraryTarget: 'commonjs',
filename: webpackOutput.filename.replace('.js', '.node.js')
},
externals: /^(@babel\/runtime|core-js|@ecomplus\/utils|axios)/i
})

webpack(webpackConfigList, (err, stats) => {
// console.log(stats)
if (err) {
Expand All @@ -67,7 +84,7 @@ webpack(webpackConfigList, (err, stats) => {
// check and handle webpack errors and warnings
const info = stats.toJson()
if (stats.hasErrors()) {
let err = info.errors
const err = info.errors
fatalError(err)
}
if (stats.hasWarnings()) {
Expand Down

0 comments on commit 20d0f3d

Please sign in to comment.