Repository navigation
Using with @rollup/plugin-multi-entry plugin and custom transform #1613
Replies: 1 comment
|
For the two different outputs you describe, use two configurations: one for the existing concatenated/minified library, one for the TypeScript modules. Neither needs // rollup.config.mjs
import fs from 'node:fs'; // used by the existing concatenation helpers
import path from 'node:path';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
const legacyEntry = path.resolve('javascript/src/js/lib.js');
function handleDependencies() {
return {
name: 'handleDependencies',
transform(content, id) {
if (id !== legacyEntry) return null;
// content is now the actual legacy entry source, not export statements.
return {
code: combineDependencies(getDependencies(content)),
map: null,
};
},
};
}
export default [
{
input: legacyEntry,
plugins: [handleDependencies()],
output: [
{ file: 'javascript/output/lib.js', format: 'cjs', strict: false },
{
file: 'javascript/output/lib.min.js',
format: 'cjs', strict: false, plugins: [terser()],
},
],
},
{
// List every TS file that must be an entry, even if nothing imports it.
input: ['javascript/test.ts'],
plugins: [typescript({ tsconfig: './tsconfig.json' })],
output: {
dir: 'javascript/output',
format: 'cjs',
preserveModules: true,
preserveModulesRoot: 'javascript',
},
},
];
// Keep your getDependencies/combineDependencies helpers here.A minimal matching {
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"rootDir": "javascript",
"declaration": true,
"declarationDir": "javascript/output/types"
},
"include": ["javascript/**/*.ts"],
"exclude": ["javascript/output"]
}Keep the declaration output under the Rollup output directory. Avoid output-name collisions when adding entries. If your package uses The important custom-plugin change is the I checked the graph-loss behavior with a minimal fixture on Rollup 4.52.5, References: transform hook, preserveModules, multi-entry documentation. |
Uh oh!
There was an error while loading. Please reload this page.
Hello. I am new to rollup and its plugin usage and environment. Sorry if this already has a solution, I have not came across.
I have a library written in JS and some classes in TS. I have a custom transform plugin, which goes through all the needed JS files and combines/minifies in a single output file. This is what I wanted and all is good.
However, I also want to have my TS files compiled into JS as seperate modules. To handle multiple inputs, I've used
@rollup/plugin-multi-entryplugin. This changed how I handled the transform plugin a little bit, due to loaded content being a list of files to be exported instead of singular input file's content. However, I cannot process the rest of my files once I return from transform. I get a.d.tsfile per.tsfile, but not the implementation codes. I get the implementation code correctly if I plain run it without my custom plugin for combining the dependencies. Here is the code:All reactions