Skip to content

Commit

Permalink
fix(config): use jsVarName for moduleName
Browse files Browse the repository at this point in the history
  • Loading branch information
redallen committed Feb 18, 2021
1 parent 34af89a commit d054eca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/config/federated-modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { resolve } = require('path');
const { ModuleFederationPlugin } = require('webpack').container;
const jsVarName = require('./src/jsVarName');

module.exports = ({
root,
Expand All @@ -11,7 +12,7 @@ module.exports = ({
exclude = []
}) => {
const { dependencies, insights } = require(resolve(root, './package.json')) || {};
const appName = moduleName || (insights && insights.appname);
const appName = moduleName || (insights && jsVarName(insights.appname));

let sharedDeps = [
{ lodash: { singleton: true, ...dependencies.lodash && { requiredVersion: dependencies.lodash } } },
Expand Down
11 changes: 11 additions & 0 deletions packages/config/src/jsVarName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function jsVarName(s) {
return s
// Camel case dashes
.replace(/-(\w)/g, (_, match) => match.toUpperCase())
// Remove leading digits
.replace(/^[0-9]+/, '')
// Remove all non alphanumeric chars
.replace(/[^A-Za-z0-9]+/g, '');
}

module.exports = jsVarName;
3 changes: 2 additions & 1 deletion packages/config/src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ExtractCssWebpackPlugin = new(require('mini-css-extract-plugin'))({
});
const CleanWebpackPlugin = new(require('clean-webpack-plugin').CleanWebpackPlugin)({ cleanStaleWebpackAssets: false });
const WebpackHotModuleReplacement = new HotModuleReplacementPlugin();
const jsVarName = require('./jsVarName');

module.exports = ({
rootFolder,
Expand All @@ -41,7 +42,7 @@ module.exports = ({
]);

const ChunkMapper = new(require('../chunk-mapper'))({ modules: [
...insights ? [ insights.appname ] : [],
...insights ? [ jsVarName(insights.appname) ] : [],
...modules || []
] });

Expand Down

0 comments on commit d054eca

Please sign in to comment.