From a82787d899d85ee391d34c4e868e397aecf66fe9 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 14 Sep 2016 16:20:16 +0200 Subject: [PATCH] Add support for -d option (to generate source-maps) * Add support for -d option (to generate source-maps) * Fix tests on Windows 7/10 (Note that 2 tests still fail ?) --- README.md | 1 + index.js | 8 ++++++++ lib/validate.js | 13 +++++++++++++ package.json | 2 +- tests/validate.test.js | 14 +++++++------- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8dfdca288..70065c07c 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ serverless webpack --out dist Options are: - `--out` or `-o` (optional) The output directory. Defaults to `.webpack`. +- `--debug` or `-d` (optional) Debug. To include source maps. ## Example with Babel diff --git a/index.js b/index.js index 73160b67a..d2917019a 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,14 @@ class ServerlessWebpack { usage: 'Path to output directory', shortcut: 'o', }, + debug: { + usage: 'Debug. To include source maps', + shortcut: 'd', + }, + // 'optimize-minimize': { + // usage: 'Optimize and minimize for production', + // shortcut: 'm', + // } }, commands: { invoke: { diff --git a/lib/validate.js b/lib/validate.js index 5c2e2eeea..9bbf25ffd 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -46,6 +46,19 @@ module.exports = { this.webpackConfig.output.path = path.join(this.serverless.config.servicePath, this.options.out); } + // Debug + if (this.options.debug) { + this.webpackConfig.devtool = 'source-map'; + } + + // Optimize and Minimize + // if (this.options['optimize-minimize']) { + // if (this.webpackConfig.plugins === undefined) { + // this.webpackConfig.plugins = []; + // } + // this.webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })); + // } + fse.removeSync(this.webpackConfig.output.path); return BbPromise.resolve(); diff --git a/package.json b/package.json index 03831b08f..b5a653559 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "homepage": "https://github.com/elastic-coders/serverless-webpack#readme", "scripts": { - "test": "istanbul cover _mocha tests/all -- -R spec --recursive" + "test": "istanbul cover node_modules/mocha/bin/_mocha tests/all -- -R spec --recursive" }, "dependencies": { "bluebird": "^3.4.0", diff --git a/tests/validate.test.js b/tests/validate.test.js index e251f9587..7449dfab9 100644 --- a/tests/validate.test.js +++ b/tests/validate.test.js @@ -90,7 +90,7 @@ describe('validate', () => { .validate() .then(() => { expect(module.webpackConfig.output).to.eql({ - path: `${testServicePath}/${testOptionsOut}`, + path: path.join(`${testServicePath}`, `${testOptionsOut}`), filename: 'filename', }); }); @@ -125,7 +125,7 @@ describe('validate', () => { .then(() => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', - path: `${testServicePath}/.webpack`, + path: path.join(`${testServicePath}`, '.webpack'), filename: testEntry, }); }); @@ -144,7 +144,7 @@ describe('validate', () => { .then(() => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', - path: `${testServicePath}/.webpack`, + path: path.join(`${testServicePath}`, '.webpack'), filename: 'last', }); }); @@ -160,7 +160,7 @@ describe('validate', () => { .then(() => { expect(module.webpackConfig.output).to.eql({ libraryTarget: 'commonjs', - path: `${testServicePath}/.webpack`, + path: path.join(`${testServicePath}`, '.webpack'), filename: 'handler.js', }); }); @@ -171,7 +171,7 @@ describe('validate', () => { it('should load a webpack config from file if `custom.webpack` is a string', () => { const testConfig = 'testconfig' const testServicePath = 'testpath'; - const requiredPath = `${testServicePath}/${testConfig}`; + const requiredPath = path.join(`${testServicePath}`, `${testConfig}`); module.serverless.config.servicePath = testServicePath; module.serverless.service.custom.webpack = testConfig; serverless.utils.fileExistsSync = sinon.stub().returns(true); @@ -191,7 +191,7 @@ describe('validate', () => { it('should throw if providing an invalid file', () => { const testConfig = 'testconfig' const testServicePath = 'testpath'; - const requiredPath = `${testServicePath}/${testConfig}`; + const requiredPath = path.join(`${testServicePath}`, `${testConfig}`); module.serverless.config.servicePath = testServicePath; module.serverless.service.custom.webpack = testConfig; serverless.utils.fileExistsSync = sinon.stub().returns(false); @@ -204,7 +204,7 @@ describe('validate', () => { it('should load a default file if no custom config is provided', () => { const testConfig = 'webpack.config.js'; const testServicePath = 'testpath'; - const requiredPath = `${testServicePath}/${testConfig}`; + const requiredPath = path.join(`${testServicePath}`, `${testConfig}`); module.serverless.config.servicePath = testServicePath; serverless.utils.fileExistsSync = sinon.stub().returns(true); const loadedConfig = {