Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
13 changes: 13 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('validate', () => {
.validate()
.then(() => {
expect(module.webpackConfig.output).to.eql({
path: `${testServicePath}/${testOptionsOut}`,
path: path.join(`${testServicePath}`, `${testOptionsOut}`),
filename: 'filename',
});
});
Expand Down Expand Up @@ -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,
});
});
Expand All @@ -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',
});
});
Expand All @@ -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',
});
});
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 = {
Expand Down