Files

74 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
2018-03-07 01:20:15 +01:00
/**
* Plugin configuration.
*/
const _ = require('lodash');
/**
* Plugin defaults
*/
const DefaultConfig = {
webpackConfig: 'webpack.config.js',
includeModules: false,
2018-03-07 01:20:15 +01:00
packager: 'npm',
2018-03-08 02:57:03 +01:00
packagerOptions: {},
2018-03-07 01:20:15 +01:00
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;
2018-03-07 01:20:15 +01:00
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;
2018-03-07 01:20:15 +01:00
}
get packager() {
return this._config.packager;
}
2018-03-08 02:57:03 +01:00
get packagerOptions() {
return this._config.packagerOptions;
}
2018-03-07 01:20:15 +01:00
get config() {
return this._config.config;
}
get hasLegacyConfig() {
return this._hasLegacyConfig;
}
toJSON() {
return _.omitBy(this._config, _.isNil);
}
}
module.exports = Configuration;