Build: Add rollup-plugin-polyfill-node (#10249)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-02-08 09:50:43 +08:00
1 parent ba3930d63e
commit a1ba8fb812
5 files changed
+24 -97

No files matched your search

+4 -6
View File
@@ -7,12 +7,11 @@ const webpack = require("webpack");
const { nodeResolve } = require("@rollup/plugin-node-resolve");
const rollupPluginAlias = require("@rollup/plugin-alias");
const commonjs = require("@rollup/plugin-commonjs");
const nodeGlobals = require("rollup-plugin-node-globals");
const rollupPluginPolyfillNode = require("rollup-plugin-polyfill-node");
const json = require("@rollup/plugin-json");
const replace = require("@rollup/plugin-replace");
const { terser } = require("rollup-plugin-terser");
const { babel } = require("@rollup/plugin-babel");
const nativeShims = require("./rollup-plugins/native-shims");
const executable = require("./rollup-plugins/executable");
const evaluate = require("./rollup-plugins/evaluate");
const externals = require("./rollup-plugins/externals");
@@ -130,7 +129,8 @@ function getRollupConfig(bundle) {
// ignore `MIXED_EXPORTS` warn
warning.code === "MIXED_EXPORTS" ||
(warning.code === "CIRCULAR_DEPENDENCY" &&
warning.importer.startsWith("node_modules"))
(warning.importer.startsWith("node_modules") ||
warning.importer.startsWith("polyfill-node:")))
) {
return;
}
@@ -183,8 +183,6 @@ function getRollupConfig(bundle) {
evaluate(),
json(),
rollupPluginAlias(alias),
bundle.target === "universal" &&
nativeShims(path.resolve(__dirname, "shims")),
nodeResolve({
extensions: [".js", ".json"],
preferBuiltins: bundle.target === "node",
@@ -199,7 +197,7 @@ function getRollupConfig(bundle) {
requireReturnsDefault: "preferred",
}),
externals(bundle.externals),
bundle.target === "universal" && nodeGlobals(),
bundle.target === "universal" && rollupPluginPolyfillNode(),
babel(babelConfig),
bundle.minify !== false &&
bundle.target === "universal" &&
+3
View File
@@ -45,6 +45,9 @@ const parsers = [
"extra.projects = prepareAndTransformProjects(":
"extra.projects = [] || prepareAndTransformProjects(",
"process.versions.node": "'999.999.999'",
// `rollup-plugin-polyfill-node` don't have polyfill for these modules
'require("perf_hooks")': "{}",
'require("inspector")': "{}",
},
},
{
@@ -1,34 +0,0 @@
"use strict";
const fs = require("fs");
const path = require("path");
const builtins = require("builtin-modules");
const EMPTY = "export default {};";
const PREFIX = "\0shim:";
module.exports = function (dir) {
return {
resolveId(importee) {
if (importee.startsWith(PREFIX)) {
return importee;
}
if (/\0/.test(importee) || !builtins.includes(importee)) {
return null;
}
const shim = path.resolve(dir, importee + ".mjs");
if (fs.existsSync(shim)) {
return shim;
}
return PREFIX + importee;
},
load(id) {
if (id.startsWith(PREFIX)) {
return EMPTY;
}
},
};
};