Skip to content

Commit

Permalink
fix: config.resolve.fallback module error
Browse files Browse the repository at this point in the history
  • Loading branch information
fupengl committed May 24, 2022
1 parent 8f23326 commit cf37e05
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function rewiredSingleSpa({
// support reactFastRefresh
config.entry = isEnvProduction
? inputEntry
: [require.resolve("react-dev-utils/webpackHotDevClient"), inputEntry];
: ["react-dev-utils/webpackHotDevClient", inputEntry];
config.output.jsonpFunction = `webpackJsonp_${safeVarName(projectName)}`;
config.output.hotUpdateFunction = `webpackHotUpdate_${safeVarName(
projectName
Expand Down Expand Up @@ -159,17 +159,20 @@ function rewiredSingleSpa({
Buffer: ["buffer", "Buffer"],
})
);
config.resolve.fallback = Object.assign(config.resolve.fallback || {}, {
url: require.resolve("url"),
fs: require.resolve("fs"),
assert: require.resolve("assert"),
crypto: require.resolve("crypto-browserify"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify/browser"),
buffer: require.resolve("buffer"),
stream: require.resolve("stream-browserify"),
});
config.resolve.fallback = Object.assign(
config.resolve.fallback || {},
getFallbackObj({
url: "url",
fs: "fs",
assert: "assert",
crypto: "crypto-browserify",
http: "stream-http",
https: "https-browserify",
os: "os-browserify/browser",
buffer: "buffer",
stream: "stream-browserify",
})
);
}

return config;
Expand Down Expand Up @@ -222,7 +225,7 @@ function disableCSSExtraction(config) {
if (x.use && Array.isArray(x.use)) {
x.use.forEach((use) => {
if (use.loader && use.loader.includes("mini-css-extract-plugin")) {
use.loader = require.resolve("style-loader/dist/cjs.js");
use.loader = "style-loader/dist/cjs.js";
delete use.options;
}
});
Expand All @@ -231,3 +234,14 @@ function disableCSSExtraction(config) {
}
}
}

function getFallbackObj(obj) {
const res = {};
for (const [k, v] of Object.entries(obj)) {
try {
const p = v;
url && (res[k] = p);
} catch (e) { }
}
return res;
}

0 comments on commit cf37e05

Please sign in to comment.