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

101 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-01-26 18:50:35 +01:00
import fs from 'fs';
2017-11-23 14:45:22 +01:00
import replace from 'rollup-plugin-replace';
2017-08-20 17:56:21 +02:00
import resolve from 'rollup-plugin-node-resolve';
2017-06-25 00:58:21 +02:00
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
2019-01-26 18:50:35 +01:00
import sucrase from 'rollup-plugin-sucrase';
2017-06-25 00:58:21 +02:00
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;
2017-06-25 00:58:21 +02:00
export default [
2019-01-26 18:50:35 +01:00
/* internal.[m]js */
{
input: `src/internal/index.js`,
output: [
{
file: `internal.mjs`,
format: 'esm',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
},
{
file: `internal.js`,
format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
}
],
external: id => id.startsWith('svelte/'),
plugins: [{
generateBundle(options, bundle) {
const mod = bundle['internal.mjs'];
if (mod) {
fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
}
}
}]
},
/* compiler.js */
2017-06-25 00:58:21 +02:00
{
2017-08-20 17:09:05 +02:00
input: 'src/index.ts',
2017-06-25 00:58:21 +02:00
plugins: [
2017-11-23 14:45:22 +01:00
replace({
__VERSION__: pkg.version
}),
2019-01-27 02:52:56 +01:00
resolve(),
2019-01-26 18:50:35 +01:00
commonjs({
include: ['node_modules/**']
}),
2017-06-25 00:58:21 +02:00
json(),
2019-01-26 18:50:35 +01:00
is_publish
? typescript({
include: 'src/**',
exclude: 'src/internal/**',
typescript: require('typescript')
})
: sucrase({
transforms: ['typescript']
})
2017-06-25 00:58:21 +02:00
],
2017-08-20 17:09:05 +02:00
output: {
file: 'compiler.js',
2019-01-26 18:50:35 +01:00
format: is_publish ? 'umd' : 'cjs',
2017-08-20 17:09:05 +02:00
name: 'svelte',
2019-01-26 18:50:35 +01:00
sourcemap: true,
},
external: is_publish
? []
: id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree')
2017-06-25 00:58:21 +02:00
},
2019-01-26 18:50:35 +01:00
/* motion.mjs */
{
input: `src/motion/index.js`,
output: [
{
2019-01-26 18:50:35 +01:00
file: `motion.mjs`,
2019-01-01 22:54:50 +01:00
format: 'esm',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
},
{
2019-01-26 18:50:35 +01:00
file: `motion.js`,
2019-01-01 22:54:50 +01:00
format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
}
2019-01-01 22:54:50 +01:00
],
external: id => id.startsWith('svelte/')
2019-01-26 18:50:35 +01:00
},
2019-01-01 22:54:50 +01:00
// everything else
2018-12-23 22:51:50 +01:00
...['index', 'store', 'easing', 'transition'].map(name => ({
input: `${name}.mjs`,
2017-08-20 17:09:05 +02:00
output: {
2018-12-23 22:51:50 +01:00
file: `${name}.js`,
2019-01-01 22:54:50 +01:00
format: 'cjs',
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
},
2018-12-23 22:51:50 +01:00
external: id => id !== `${name}.mjs`
}))
2017-06-25 00:58:21 +02:00
];