UNPKG

@oriflame/config-webpack

Version:
149 lines (113 loc) 3.94 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const core = require('@beemo/core'); const lumosCommon = require('@oriflame/lumos-common'); const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const path = require('path'); const webpack = require('webpack'); const webpackBundleAnalyzer = require('webpack-bundle-analyzer'); const constants = require('./constants2.js'); const env = require('./env2.js'); const _interopDefault = e => e && e.__esModule ? e : { default: e }; const ReactRefreshWebpackPlugin__default = /*#__PURE__*/_interopDefault(ReactRefreshWebpackPlugin); const HtmlWebpackPlugin__default = /*#__PURE__*/_interopDefault(HtmlWebpackPlugin); const path__default = /*#__PURE__*/_interopDefault(path); const webpack__default = /*#__PURE__*/_interopDefault(webpack); const WEBPACK_ROOT = process.cwd(); const PROD = process.env.NODE_ENV === 'production'; const PORT = 3000; let favicon = ''; function getFavIcon(srcPath) { if (favicon) { return favicon; } const prodPath = new core.Path(srcPath, 'favicon.png'); const devPath = new core.Path(srcPath, 'favicon-dev.png'); if (!PROD && devPath.exists()) { favicon = devPath.path(); } else if (prodPath.exists()) { favicon = prodPath.path(); } return favicon; } function getPlugins({ analyzeBundle, srcFolder, entryPoint, react, moduleFederationConfig, enableSharedModules, root, sharedModulesManifestPath }) { const srcPath = path__default.default.join(WEBPACK_ROOT, srcFolder); const plugins = [new webpack__default.default.DefinePlugin({ __DEV__: JSON.stringify(!PROD) })]; if (moduleFederationConfig) { plugins.push(new webpack.container.ModuleFederationPlugin(moduleFederationConfig)); } if (!PROD) { plugins.push(new HtmlWebpackPlugin__default.default({ template: `${srcFolder}/index.html`, filename: 'index.html', favicon: getFavIcon(srcPath) }), new webpack__default.default.DefinePlugin(env('development'))); } if (PROD && enableSharedModules) { plugins.push(new webpack__default.default.DllReferencePlugin({ context: root, manifest: require.resolve(`@ori/shared-libs/${sharedModulesManifestPath}`) })); } if (analyzeBundle) { // @ts-expect-error -- error plugins.push(new webpackBundleAnalyzer.BundleAnalyzerPlugin()); } if (!entryPoint && PROD) { plugins.push(new HtmlWebpackPlugin__default.default({ chunksSortMode: 'auto', template: `${srcFolder}/index.html`, filename: 'index.html', favicon: getFavIcon(srcPath) })); } if (react && !PROD) { plugins.push(new ReactRefreshWebpackPlugin__default.default()); } plugins.push(new webpack__default.default.NormalModuleReplacementPlugin(/^node:/, resource => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, no-param-reassign -- `NormalModuleReplacementPlugin` has bad typings resource.request = resource.request.replace(/^node:/, ''); })); return plugins; } function getUniqueName() { const _lumosCommon$getRootP = lumosCommon.getRootPackageJson(), name = _lumosCommon$getRootP.name; return `${name.replace(constants.NUMBER_REGEX, '').replace(constants.INVALID_CHARS, '')}`; } function getParallelValue(value) { if (value === undefined) { return true; } if (value === 'true') { return true; } if (value === 'false' || value === '') { return false; } return Number(value || 1); } exports.PORT = PORT; exports.PROD = PROD; exports.WEBPACK_ROOT = WEBPACK_ROOT; exports.getFavIcon = getFavIcon; exports.getParallelValue = getParallelValue; exports.getPlugins = getPlugins; exports.getUniqueName = getUniqueName; //# sourceMappingURL=helpers2.js.map