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
2020-11-23 17:23:03 +01:00
fs . writeFileSync ( ` ./compiler.d.ts ` , ` export { compile, parse, preprocess, walk, 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 ` ,
2018-12-22 06:42:44 +01:00
output : [
{
2019-05-27 21:36:02 +02:00
file : ` index.mjs ` ,
2019-01-01 22:54:50 +01:00
format : 'esm' ,
2020-11-09 15:57:40 +01:00
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '.' ) } /index.mjs `
2018-12-22 06:42:44 +01:00
} ,
{
2019-05-27 21:36:02 +02:00
file : ` index.js ` ,
2019-01-01 22:54:50 +01:00
format : 'cjs' ,
2020-11-09 15:57:40 +01:00
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '.' ) } /index.js `
2018-12-22 06:42:44 +01:00
}
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
} ,
2018-12-22 06:42:44 +01:00
2021-06-29 04:17:16 +02:00
{
input : ` src/runtime/ssr.ts ` ,
output : [
{
file : ` ssr.mjs ` ,
format : 'esm' ,
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '.' ) } /index.mjs `
} ,
{
file : ` ssr.js ` ,
format : 'cjs' ,
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '.' ) } /index.js `
}
] ,
external ,
plugins : [ ts _plugin ]
} ,
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' ,
2020-11-09 15:57:40 +01:00
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '..' ) } /index.mjs `
2019-05-27 21:36:02 +02:00
} ,
{
file : ` ${ dir } /index.js ` ,
format : 'cjs' ,
2020-11-09 15:57:40 +01:00
paths : id => id . startsWith ( 'svelte/' ) && ` ${ id . replace ( 'svelte' , '..' ) } /index.js `
2019-05-27 21:36:02 +02:00
}
] ,
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 ) {
2019-06-24 20:50:26 +02:00
fs . writeFileSync ( 'src/compiler/compile/internal_exports.ts' , ` // This file is automatically generated \n export 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 ( {
2022-11-10 15:10:40 +01:00
_ _VERSION _ _ : pkg . version ,
'process.env.NODE_DEBUG' : false // appears inside the util package
2019-05-27 21:58:26 +02:00
} ) ,
2022-11-10 15:10:40 +01:00
{
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
}
}
} ,
2019-05-27 21:58:26 +02:00
resolve ( ) ,
commonjs ( {
include : [ 'node_modules/**' ]
} ) ,
json ( ) ,
ts _plugin
] ,
2020-08-14 05:36:55 +02:00
output : [
{
file : 'compiler.js' ,
format : is _publish ? 'umd' : 'cjs' ,
name : 'svelte' ,
sourcemap : true ,
} ,
{
file : 'compiler.mjs' ,
format : 'esm' ,
name : 'svelte' ,
sourcemap : true ,
}
] ,
2019-05-27 21:58:26 +02:00
external : is _publish
? [ ]
: id => id === 'acorn' || id === 'magic-string' || id . startsWith ( 'css-tree' )
}
2017-06-25 00:58:21 +02:00
] ;