Files
serverless-webpack/lib/Configuration.js
T
Frank Schmid bcd8dd65e6 Yarn support
Unit tests

Added unit tests for copy modules packager flag

npm must copy modules

Fixed unit tests

Yarn does not need to copy modules to be fast

Install/prune unit tests. Fixed typo.

Copy lock file only if it can be read. AAdjust unit tests.

Copy lock file into function directories

Only stringify JSON or YML lock files

Fixed unit tests

Add basic Yarn functionality
2018-03-09 11:25:58 +01:00

83 lines
1.7 KiB
JavaScript

'use strict';
/**
* Plugin configuration.
*/
const _ = require('lodash');
/**
* Plugin defaults
*/
const DefaultConfig = {
webpackConfig: 'webpack.config.js',
includeModules: false,
packager: 'npm',
packagerOptions: {},
packExternalModulesMaxBuffer: 200 * 1024,
config: null
};
class Configuration {
constructor(custom) {
this._config = {};
this._hasLegacyConfig = false;
// Set configuration from sls.service.custom. We fall back to the
// old configuration to keep backwards compatibility.
if (custom) {
if (custom.webpackIncludeModules) {
this._config.includeModules = custom.webpackIncludeModules;
this._hasLegacyConfig = true;
}
if (custom.packExternalModulesMaxBuffer) {
this._config.packExternalModulesMaxBuffer = custom.packExternalModulesMaxBuffer;
this._hasLegacyConfig = true;
}
if (_.isString(custom.webpack)) {
this._config.webpackConfig = custom.webpack;
this._hasLegacyConfig = true;
} else {
_.assign(this._config, custom.webpack || {});
}
}
// Set defaults for all missing properties
_.defaults(this._config, DefaultConfig);
}
get webpackConfig() {
return this._config.webpackConfig;
}
get includeModules() {
return this._config.includeModules;
}
get packExternalModulesMaxBuffer() {
return this._config.packExternalModulesMaxBuffer;
}
get packager() {
return this._config.packager;
}
get packagerOptions() {
return this._config.packagerOptions;
}
get config() {
return this._config.config;
}
get hasLegacyConfig() {
return this._hasLegacyConfig;
}
toJSON() {
return _.omitBy(this._config, _.isNil);
}
}
module.exports = Configuration;