|
| 1 | +import { babel } from '@rollup/plugin-babel'; |
| 2 | +import babelPluginPresetReact from '@babel/preset-react'; |
| 3 | + |
| 4 | +import typescript from '@rollup/plugin-typescript'; |
| 5 | +import resolve from '@rollup/plugin-node-resolve'; |
| 6 | +import externals from 'rollup-plugin-node-externals'; |
| 7 | + |
| 8 | +import babelPluginSyntaxTypescript from '@babel/plugin-syntax-typescript'; |
| 9 | +import babelPluginJsxToLiterals from '@gracile-labs/babel-plugin-jsx-to-literals/babel-plugin'; |
| 10 | +import babelPluginJsxMeta from '@gracile-labs/babel-plugin-jsx-to-literals/babel-plugin-meta'; |
| 11 | +import babelPluginVue from '@vue/babel-plugin-jsx'; |
| 12 | +// import babelPresetSolid from 'babel-preset-solid'; |
| 13 | + |
| 14 | +import { defineConfig, type RollupOptions } from 'rollup'; |
| 15 | + |
| 16 | +const extensions = ['.js', '.ts', '.tsx']; |
| 17 | + |
| 18 | +const common = { |
| 19 | + input: './src/index.framework.ts', |
| 20 | + output: { |
| 21 | + format: 'es', |
| 22 | + sourcemap: true, |
| 23 | + preserveModules: true, |
| 24 | + }, |
| 25 | + plugins: [externals(), resolve({ extensions })], |
| 26 | + external: (id) => { |
| 27 | + // for link and workspace protocol |
| 28 | + return ( |
| 29 | + id.includes('/@gracile') || |
| 30 | + // id.includes('/@jsfe/engine') || |
| 31 | + id.includes('/@jsfe/generics') || |
| 32 | + id === 'preact' || |
| 33 | + id.includes('/preact-jsx-runtime') |
| 34 | + ); |
| 35 | + }, |
| 36 | +} as const satisfies RollupOptions; |
| 37 | + |
| 38 | +const babelCommonSettings = { |
| 39 | + extensions, |
| 40 | + sourceType: 'unambiguous', |
| 41 | + babelHelpers: 'bundled', // NOTE: Explicit default. |
| 42 | +} as const; |
| 43 | + |
| 44 | +const tsFrameworkIncludes = [ |
| 45 | + 'src/index.framework.ts', |
| 46 | + 'src/widgets/*.tsx', |
| 47 | + 'src/form.tsx', |
| 48 | + 'src/form-generic.tsx', |
| 49 | + 'src/types.ts', |
| 50 | +]; |
| 51 | + |
| 52 | +const enabled = { |
| 53 | + lit: true, |
| 54 | + preact: true, |
| 55 | + react: true, |
| 56 | + vue: true, |
| 57 | +}; |
| 58 | + |
| 59 | +const options: RollupOptions[] = []; |
| 60 | + |
| 61 | +// --- |
| 62 | + |
| 63 | +if (enabled.lit) |
| 64 | + options.push({ |
| 65 | + ...common, |
| 66 | + input: './src/index.ts', |
| 67 | + output: { ...common.output, dir: 'dist/lit' }, |
| 68 | + plugins: [ |
| 69 | + ...common.plugins, |
| 70 | + typescript({ |
| 71 | + outDir: 'dist/lit', |
| 72 | + include: [ |
| 73 | + 'src/index.ts', |
| 74 | + 'src/widgets/*.tsx', |
| 75 | + 'src/form.tsx', |
| 76 | + 'src/form-generic.tsx', |
| 77 | + 'src/elements.tsx', |
| 78 | + 'src/types.ts', |
| 79 | + ], |
| 80 | + // transformers: { |
| 81 | + // after: [compileLitTemplates()], |
| 82 | + // }, |
| 83 | + }), |
| 84 | + babel({ |
| 85 | + ...babelCommonSettings, |
| 86 | + plugins: [ |
| 87 | + [babelPluginSyntaxTypescript, { isTSX: true }], |
| 88 | + [babelPluginJsxToLiterals], |
| 89 | + ], |
| 90 | + }), |
| 91 | + ], |
| 92 | + }); |
| 93 | + |
| 94 | +if (enabled.preact) |
| 95 | + options.push({ |
| 96 | + ...common, |
| 97 | + output: { ...common.output, dir: 'dist/preact' }, |
| 98 | + plugins: [ |
| 99 | + ...common.plugins, |
| 100 | + typescript({ outDir: 'dist/preact', include: tsFrameworkIncludes }), |
| 101 | + babel({ |
| 102 | + ...babelCommonSettings, |
| 103 | + plugins: [[babelPluginJsxMeta, { framework: 'preact' }]], |
| 104 | + presets: [ |
| 105 | + [ |
| 106 | + babelPluginPresetReact, |
| 107 | + { runtime: 'automatic', importSource: 'preact-jsx-runtime' }, |
| 108 | + ], |
| 109 | + ], |
| 110 | + }), |
| 111 | + ], |
| 112 | + }); |
| 113 | + |
| 114 | +if (enabled.react) |
| 115 | + options.push({ |
| 116 | + ...common, |
| 117 | + output: { ...common.output, dir: 'dist/react' }, |
| 118 | + plugins: [ |
| 119 | + ...common.plugins, |
| 120 | + typescript({ outDir: 'dist/react', include: tsFrameworkIncludes }), |
| 121 | + babel({ |
| 122 | + ...babelCommonSettings, |
| 123 | + plugins: [[babelPluginJsxMeta, { framework: 'react' /* (default) */ }]], |
| 124 | + presets: [[babelPluginPresetReact, { runtime: 'automatic' }]], |
| 125 | + }), |
| 126 | + ], |
| 127 | + }); |
| 128 | + |
| 129 | +if (enabled.vue) |
| 130 | + options.push({ |
| 131 | + ...common, |
| 132 | + output: { ...common.output, dir: 'dist/vue' }, |
| 133 | + plugins: [ |
| 134 | + ...common.plugins, |
| 135 | + typescript({ outDir: 'dist/vue', include: tsFrameworkIncludes }), |
| 136 | + babel({ |
| 137 | + ...babelCommonSettings, |
| 138 | + plugins: [[babelPluginJsxMeta, { framework: 'vue' }], babelPluginVue], |
| 139 | + }), |
| 140 | + ], |
| 141 | + }); |
| 142 | + |
| 143 | +export default defineConfig(options); |
| 144 | + |
| 145 | +// { |
| 146 | +// ...common, |
| 147 | +// output: { ...common.output, dir: 'dist/solid' }, |
| 148 | +// plugins: [ |
| 149 | +// ...common.plugins, |
| 150 | +// typescript({ outDir: 'dist/solid', include: tsFrameworkIncludes }), |
| 151 | +// babel({ |
| 152 | +// ...babelCommonSettings, |
| 153 | +// plugins: [[babelPluginJsxMeta, { framework: 'solid' }]], |
| 154 | +// presets: [babelPresetSolid], |
| 155 | +// }), |
| 156 | +// ], |
| 157 | +// }, |
0 commit comments