You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/rollup.config.js

83 lines
2.5 KiB

import fs from 'node:fs';
import { createRequire } from 'node:module';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
const require = createRequire(import.meta.url);
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
// Create auto-generated .js files
fs.writeFileSync(
'./src/shared/version.js',
`/** @type {string} */\nexport const VERSION = '${pkg.version}';`
);
const internal = await import('./src/runtime/internal/index.js');
fs.writeFileSync(
'src/compiler/compile/internal_exports.js',
`// This file is automatically generated\n` +
`export default new Set(${JSON.stringify(Object.keys(internal))});`
);
// Generate d.ts files for runtime entrypoints so that TS can find it also without `"moduleResolution": "bundler"`
fs.readdirSync('src/runtime', { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.forEach((dirent) =>
fs.writeFileSync(
`${dirent.name}.d.ts`,
`export * from './types/runtime/${dirent.name}/index.js';`
)
);
fs.writeFileSync('./index.d.ts', `export * from './types/runtime/index.js';`);
fs.writeFileSync(
'./compiler.d.ts',
`export { compile, parse, preprocess, walk, VERSION } from './types/compiler/index.js';`
);
/**
* @type {import("rollup").RollupOptions[]}
*/
export default [
// Generate UMD build of the compiler so that Eslint/Prettier (which need CJS) and REPL (which needs UMD because browser) can use it
{
input: 'src/compiler/index.js',
plugins: [
replace({
preventAssignment: true,
values: {
'process.env.NODE_DEBUG': false // appears inside the util package
}
}),
{
resolveId(id) {
// util is a built-in module in Node.js, but we want a self-contained compiler bundle
// that also works in the browser, so we load its polyfill instead
if (id === 'util') {
return require.resolve('./node_modules/util'); // just 'utils' would resolve this to the built-in module
}
// Must import from the `css-tree` browser bundled distribution due to `createRequire` usage if importing from css-tree directly
if (id === 'css-tree') {
return require.resolve('./node_modules/css-tree/dist/csstree.esm.js');
}
}
},
resolve(),
commonjs({
include: ['node_modules/**']
}),
json()
],
output: {
file: 'compiler.cjs',
format: 'umd',
name: 'svelte',
sourcemap: false
},
external: []
}
];