Tony Yuen
8 years ago
3 changed files with 54 additions and 2 deletions
@ -0,0 +1,44 @@ |
|||
'use strict'; |
|||
|
|||
const BbPromise = require('bluebird'); |
|||
const webpack = require('webpack'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const npm = require('npm-programmatic'); |
|||
|
|||
module.exports = { |
|||
packExternalModules() { |
|||
|
|||
this.serverless.cli.log(this.webpackOutputPath); |
|||
|
|||
this.serverless.cli.log(JSON.stringify(this.webpackConfig.externals)); |
|||
|
|||
const externals = this.webpackConfig.externals; |
|||
|
|||
return BbPromise.resolve().then(() => { |
|||
if (!externals || externals.length === 0) { |
|||
return; |
|||
} |
|||
|
|||
this.serverless.cli.log('packing external modules'); |
|||
|
|||
const tmpPackageJson = path.join(this.webpackOutputPath, 'package.json'); |
|||
|
|||
// create a temp package.json in dist directory so that we can install the dependencies later.
|
|||
fs.writeFileSync(tmpPackageJson, "{}"); |
|||
|
|||
return new BbPromise((resolve, reject) => { |
|||
npm.install(externals, { |
|||
cwd: this.webpackOutputPath, |
|||
save: false |
|||
}).then(() => { |
|||
fs.unlink(tmpPackageJson); |
|||
resolve() |
|||
}).catch(e => { |
|||
fs.unlink(tmpPackageJson); |
|||
reject(e); |
|||
}) |
|||
}) |
|||
}) |
|||
}, |
|||
}; |
Loading…
Reference in new issue