0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00
svelte/rollup.config.js

113 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-01-26 18:50:35 +01:00
import fs from 'fs';
2019-11-02 23:23:18 +01:00
import replace from '@rollup/plugin-replace';
2019-12-30 02:07:47 +01:00
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import sucrase from '@rollup/plugin-sucrase';
import typescript from '@rollup/plugin-typescript';
2017-11-23 14:45:22 +01:00
import pkg from './package.json';
2017-06-25 00:58:21 +02:00
2019-01-26 18:50:35 +01:00
const is_publish = !!process.env.PUBLISH;
2019-05-27 21:36:02 +02:00
const ts_plugin = is_publish
2019-05-22 05:20:43 +02:00
? typescript({
include: 'src/**',
typescript: require('typescript')
})
: sucrase({
transforms: ['typescript']
});
2019-05-27 21:36:02 +02:00
const external = id => id.startsWith('svelte/');
2019-01-26 18:50:35 +01:00
2019-10-16 16:57:23 +02:00
fs.writeFileSync(`./compiler.d.ts`, `export { compile, parse, preprocess, VERSION } from './types/compiler/index';`);
2019-06-08 03:23:48 +02:00
2019-05-27 21:36:02 +02:00
export default [
/* runtime */
2019-01-26 18:50:35 +01:00
{
2019-05-27 21:36:02 +02:00
input: `src/runtime/index.ts`,
output: [
{
2019-05-27 21:36:02 +02:00
file: `index.mjs`,
2019-01-01 22:54:50 +01:00
format: 'esm',
2019-05-27 21:36:02 +02:00
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}`
},
{
2019-05-27 21:36:02 +02:00
file: `index.js`,
2019-01-01 22:54:50 +01:00
format: 'cjs',
2019-05-27 21:36:02 +02:00
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}`
}
2019-01-01 22:54:50 +01:00
],
2019-05-27 21:36:02 +02:00
external,
plugins: [ts_plugin]
2019-01-26 18:50:35 +01:00
},
2019-05-27 21:36:02 +02:00
...fs.readdirSync('src/runtime')
.filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory())
.map(dir => ({
input: `src/runtime/${dir}/index.ts`,
output: [
{
file: `${dir}/index.mjs`,
format: 'esm',
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}`
},
{
file: `${dir}/index.js`,
format: 'cjs',
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}`
}
],
external,
2019-05-27 21:47:09 +02:00
plugins: [
2019-12-24 01:38:49 +01:00
replace({
__VERSION__: pkg.version
}),
2019-05-27 21:47:09 +02:00
ts_plugin,
2019-06-10 00:50:46 +02:00
{
writeBundle(bundle) {
if (dir === 'internal') {
const mod = bundle['index.mjs'];
if (mod) {
fs.writeFileSync('src/compiler/compile/internal_exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
2019-06-10 00:50:46 +02:00
}
2019-05-27 21:47:09 +02:00
}
2019-06-10 00:50:46 +02:00
fs.writeFileSync(`${dir}/package.json`, JSON.stringify({
main: './index',
module: './index.mjs',
types: './index.d.ts'
}, null, ' '));
fs.writeFileSync(`${dir}/index.d.ts`, `export * from '../types/runtime/${dir}/index';`);
2019-05-27 21:47:09 +02:00
}
}
]
2019-05-27 21:58:26 +02:00
})),
/* compiler.js */
{
input: 'src/compiler/index.ts',
plugins: [
replace({
__VERSION__: pkg.version
}),
resolve(),
commonjs({
include: ['node_modules/**']
}),
json(),
ts_plugin
],
output: {
file: 'compiler.js',
format: is_publish ? 'umd' : 'cjs',
name: 'svelte',
sourcemap: true,
},
external: is_publish
? []
: id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree')
}
2017-06-25 00:58:21 +02:00
];