piral-cli-webpack5
Version:
Provides debug and build capabilities for pilets and Piral instances using Webpack v5.
30 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hmrWebpackConfigEnhancer = void 0;
const webpack_1 = require("webpack");
const HotModuleServerPlugin_1 = require("./HotModuleServerPlugin");
function getHmrEntry(hmrPort) {
return hmrPort
? [
`piral-cli-webpack5/src/webpack-hot-middleware/client?path=http://localhost:${hmrPort}/__webpack_hmr&reload=true`,
]
: [];
}
const hmrWebpackConfigEnhancer = (options) => (compilerOptions) => {
const { port } = options;
if (port) {
if (Array.isArray(compilerOptions.entry)) {
compilerOptions.entry.unshift(...getHmrEntry(port));
}
const newPlugins = [new webpack_1.HotModuleReplacementPlugin(), new HotModuleServerPlugin_1.HotModuleServerPlugin(port)];
if (!compilerOptions.plugins) {
compilerOptions.plugins = newPlugins;
}
else if (Array.isArray(compilerOptions.plugins)) {
compilerOptions.plugins.push(...newPlugins);
}
}
return compilerOptions;
};
exports.hmrWebpackConfigEnhancer = hmrWebpackConfigEnhancer;
//# sourceMappingURL=index.js.map