@vue-storefront/rollup-config
Version:
> Common rollup configuration used in Alokai integrations
64 lines (63 loc) • 3.01 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateServerConfig = generateServerConfig;
const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
const rollup_plugin_typescript2_1 = __importDefault(require("rollup-plugin-typescript2"));
const plugin_commonjs_1 = __importDefault(require("@rollup/plugin-commonjs"));
const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
const external_1 = require("./helpers/external");
const extensions = [".ts", ".js"];
// TODO add debug mode with advanced sourcemaps
function generateServerConfig(pkg) {
return {
input: "src/index.server.ts",
output: [
{
file: pkg.server,
format: "cjs",
sourcemap: true,
},
],
external: (id) => {
return (0, external_1.resolveExternal)(id, pkg);
},
plugins: [
(0, plugin_node_resolve_1.default)({
extensions,
}),
(0, rollup_plugin_typescript2_1.default)({ clean: true }),
(0, plugin_commonjs_1.default)({
extensions,
}),
(0, plugin_json_1.default)(),
(0, plugin_node_resolve_1.default)({
extensions,
}),
/**
* output: { file: pkg.server } in this file above always boils down to { file: 'server/index.js' }
*
* The output will be:
* - server/index.js (JS output of compiling index.server.ts, as per "output" property in this file)
* - server/index.d.ts (WRONG! This contains typedefs for the index.ts file, not the index.server.ts file)
* - server/index.server.d.ts (This contains typedefs for index.server.ts, but should be named index.d.ts to match the server/index.js file)
*
* The issue with the above outputs is that importing `@vsf-enterprise/someintegration-api/server` will throw errors,
* because you're using server/index.js with typedefs (server/index.d.ts) of a totally different file
*/
{
name: "RemoveIndexTypedefMismatch",
generateBundle: (options, bundle) => {
// these files are for the src/index.ts file, not for src/index.server.ts, so we can remove them.
delete bundle["index.d.ts"];
delete bundle["index.d.ts.map"];
// The object keys being file names is just a decoration, the actual name of the output file is in the .fileName property
bundle["index.server.d.ts"].fileName = "index.d.ts";
bundle["index.server.d.ts.map"].fileName = "index.d.ts.map";
},
},
],
};
}
;