ko
Version:
build & lint library
60 lines (59 loc) • 1.86 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fs_1 = require("fs");
const lodash_1 = require("lodash");
const utils_1 = require("../utils");
class Config {
constructor() {
this.cwd = process.cwd();
this.path = this.getConfigPath('ko.config.js');
this.generate();
}
get isDevOrBuildCommand() {
const flag = process.argv.find(arg => arg === 'dev' || arg === 'build');
return !!flag;
}
getConfigPath(path) {
const absolutePath = (0, path_1.join)(process.cwd(), path);
this.isDevOrBuildCommand &&
(0, utils_1.assert)((0, fs_1.existsSync)(absolutePath), 'ko.config.js file not exist, please check if it exist');
return absolutePath;
}
generate() {
this.origin = {};
if (this.isDevOrBuildCommand) {
this.origin = require(this.path);
}
this.current = (0, lodash_1.merge)(this.default, (0, lodash_1.cloneDeep)(this.origin));
return Object.freeze(this.current);
}
freezeWithOpts(cliOpts) {
this.cliOpts = cliOpts;
return Object.freeze((0, lodash_1.merge)(this.current, this.cliOpts));
}
get default() {
return {
cwd: this.cwd,
serve: {
host: '127.0.0.1',
port: 8080,
},
hash: true,
analyzer: false,
lessOptions: {
javascriptEnabled: true,
},
publicPath: '/',
experiment: {
speedUp: true,
minimizer: true,
enableCssModule: true,
disableLazyImports: false,
},
autoPolyfills: false,
babelIncludes: [],
};
}
}
exports.default = Config;