@rechunk/rollup-preset
Version:
Rollup configuration preset for bundling ReChunk components and modules
95 lines (93 loc) • 3.57 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
BABEL_ROLLUP_OVERRIDES: () => BABEL_ROLLUP_OVERRIDES,
default: () => withRechunk
});
module.exports = __toCommonJS(index_exports);
var import_utils = require("@rechunk/utils");
var import_plugin_babel = __toESM(require("@rollup/plugin-babel"));
var import_plugin_image = __toESM(require("@rollup/plugin-image"));
var import_plugin_node_resolve = __toESM(require("@rollup/plugin-node-resolve"));
var import_rollup_plugin_tsconfig_paths = __toESM(require("rollup-plugin-tsconfig-paths"));
var BABEL_ROLLUP_OVERRIDES = {
overrides: [
{
plugins: [
// Disable `module-resolver` to prevent module transformation conflicts with Rollup
["module-resolver", false]
]
}
]
};
async function processOptions(options) {
const pkgJSON = (0, import_utils.findClosestJSON)("package.json");
const rechunkJSON = (0, import_utils.findClosestJSON)(".rechunkrc.json");
const external = [
...Object.keys(pkgJSON.dependencies || {}),
...Object.keys(pkgJSON.peerDependencies || {}),
...rechunkJSON.external || []
];
if (typeof options.input !== "string") {
throw new Error("rechunk rollup-preset requires options.input as a string");
}
const defaultOptions = {
external,
plugins: [
(0, import_rollup_plugin_tsconfig_paths.default)(),
(0, import_plugin_node_resolve.default)({
extensions: [".ts", ".tsx", ".js", ".jsx"],
resolveOnly: [/^\.\//, /^\.\.\//]
}),
(0, import_plugin_babel.default)({
filename: options.input,
caller: {
name: "rechunk"
},
babelHelpers: "bundled",
extensions: [".ts", ".tsx"],
exclude: "node_modules/**",
...BABEL_ROLLUP_OVERRIDES
}),
(0, import_plugin_image.default)()
],
logLevel: "silent"
};
const { mergeAndConcat } = await import("merge-anything");
return mergeAndConcat(options, defaultOptions);
}
function withRechunk(options = {}) {
return processOptions(options);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BABEL_ROLLUP_OVERRIDES
});