UNPKG

st-bundle

Version:

CLI for watching and bundling SpringType projects.

133 lines (132 loc) 5.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const env_1 = require("../env"); const utils_1 = require("../utils/utils"); const ESSENTIAL_DEPENDENCIES = ['fuse-box-dev-import', 'tslib']; class PrivateConfig { constructor(props) { this.props = props; this.defaultSourceMapModulesRoot = '/modules'; this.json = props.json === undefined ? { useDefault: false } : props.json; if (props.cacheObject) { this.cacheObject = props.cacheObject; } this.resources = props.resources || {}; if (!this.resources.resourcePublicRoot) { this.resources.resourcePublicRoot = '/resources'; } } init(props) { this.dependencies = props.dependencies ? props.dependencies : {}; if (this.isServer()) { if (this.dependencies.ignoreAllExternal === undefined) { this.dependencies.ignoreAllExternal = true; } } // define default settings for code splitting this.codeSplitting = props.codeSplitting || {}; if (!this.codeSplitting.scriptRoot) { if (this.isServer()) { this.codeSplitting.scriptRoot = './'; } else { if (this.webIndex && this.webIndex.publicPath) { this.codeSplitting.scriptRoot = this.webIndex.publicPath; } else { this.codeSplitting.scriptRoot = '/'; } } } this.watch = { enabled: !env_1.env.isTest, }; if (props.watch !== undefined) { if (typeof props.watch === 'boolean') { this.watch.enabled = props.watch; } if (typeof props.watch === 'object') { this.watch.enabled = typeof props.watch === 'boolean' ? props.watch : true; this.watch.watcherProps = props.watch; } } // hmr ************************************************************************************************ const hmrAllowedByDefault = !env_1.env.isTest && this.target !== 'server' && this.watch.enabled; this.hmr = { enabled: hmrAllowedByDefault, hmrProps: { reloadEntryOnStylesheet: true, }, }; if (hmrAllowedByDefault && props.hmr !== undefined) { if (typeof props.hmr === 'boolean') { this.hmr.enabled = props.hmr; } if (typeof props.hmr === 'object') { this.hmr.enabled = true; this.hmr.hmrProps = Object.assign(Object.assign({}, this.hmr.hmrProps), props.hmr); } } // Plugin Link this.link = props.link ? props.link : {}; if (props.useSingleBundle !== undefined) this.useSingleBundle = props.useSingleBundle; } isEssentialDependency(name) { return ESSENTIAL_DEPENDENCIES.indexOf(name) > -1; } shoudIgnorePackage(name) { if (this.dependencies.ignoreAllExternal && !this.isEssentialDependency(name)) { return true; } if (this.dependencies.ignorePackages && this.dependencies.ignorePackages.indexOf(name) > -1) { return true; } return false; } supportsStylesheet() { return !this.isServer(); } setupEnv() { this.env = this.props.env === undefined ? { NODE_ENV: this.production ? 'production' : 'development' } : this.props.env; } isServer() { return this.target === 'server' || this.target === 'universal'; } getPublicRoot(userPublicPath) { if (userPublicPath) { return userPublicPath; } let publicPath = '/'; if (this.webIndex && this.webIndex.publicPath) { publicPath = this.webIndex.publicPath; } if (this.resources && this.resources.resourcePublicRoot) { publicPath = utils_1.joinFuseBoxPath(publicPath, this.resources.resourcePublicRoot); } return publicPath; } getResourceConfig(stylesheet) { let resources = {}; if (stylesheet) { resources.resourceFolder = stylesheet.resourceFolder || this.resources.resourceFolder; resources.resourcePublicRoot = stylesheet.resourcePublicRoot || this.resources.resourcePublicRoot; } else { resources.resourceFolder = this.resources.resourceFolder; resources.resourcePublicRoot = this.resources.resourcePublicRoot; } if (!resources.resourcePublicRoot) resources.resourcePublicRoot = '/resources'; if (resources.resourceFolder) { resources.resourceFolder = utils_1.ensureAbsolutePath(resources.resourceFolder, this.ctx.writer.outputDirectory); } else { resources.resourceFolder = path.join(this.ctx.writer.outputDirectory, resources.resourcePublicRoot); } return resources; } } exports.PrivateConfig = PrivateConfig;