UNPKG

piral-cli-webpack5

Version:

Provides debug and build capabilities for pilets and Piral instances using Webpack v5.

84 lines 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.create = void 0; const TerserPlugin = require("terser-webpack-plugin"); const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); const common_1 = require("./common"); const pilet_webpack_config_enhancer_1 = require("../enhancers/pilet-webpack-config-enhancer"); const path_1 = require("path"); const bundler_run_1 = require("./bundler-run"); const constants_1 = require("../constants"); const helpers_1 = require("../helpers"); async function getConfig(template, dist, filename, externals, importmap = [], piralInstances, schema, develop = false, sourceMaps = true, contentHash = true, minimize = true) { const production = !develop; const name = process.env.BUILD_PCKG_NAME; const version = process.env.BUILD_PCKG_VERSION; const entry = filename.replace(/\.js$/i, ''); const enhance = (0, pilet_webpack_config_enhancer_1.piletWebpackConfigEnhancer)({ name, piralInstances, version, entry, externals, importmap, schema, filename, variables: (0, common_1.getVariables)(), }); const styleLoaders = (0, common_1.getStyleLoaders)(true); return [ { devtool: sourceMaps ? (develop ? 'cheap-module-source-map' : 'source-map') : false, mode: develop ? 'development' : 'production', target: 'web', entry: { [entry]: [template], }, output: { publicPath: undefined, path: dist, filename: '[name].js', chunkFilename: contentHash ? '[chunkhash:8].js' : undefined, }, resolve: { extensions: common_1.extensions, }, module: { rules: (0, common_1.getRules)(styleLoaders), }, optimization: { minimize, minimizer: [ new TerserPlugin({ extractComments: false, terserOptions: { ie8: false, output: { comments: /^@pilet/, }, mangle: { reserved: ['__bundleUrl__'], }, }, }), new CssMinimizerPlugin(), ], }, plugins: (0, common_1.getPlugins)([], entry), }, enhance, ]; } const handler = { async create(options) { const { config = constants_1.defaultWebpackConfig } = options.args._; const otherConfigPath = (0, path_1.resolve)(options.root, config); const baseConfig = await getConfig(options.entryModule, options.outDir, options.outFile, options.externals, options.importmap, options.piralInstances, options.version, options.develop, options.sourceMaps, options.contentHash, options.minify); const wpConfig = await (0, helpers_1.extendConfig)(baseConfig, otherConfigPath, { watch: options.watch, }); return (0, bundler_run_1.runWebpack)(wpConfig, options.logLevel); }, }; exports.create = handler.create; //# sourceMappingURL=pilet.js.map