|
1 |
| -// eslint-disable-next-line import/no-extraneous-dependencies |
2 |
| -import withSolid from 'rollup-preset-solid'; |
3 |
| -import bundleSize from '@atomico/rollup-plugin-sizes'; |
4 |
| -import license from 'rollup-plugin-license'; |
| 1 | +import path from 'path'; |
| 2 | +import { babel } from '@rollup/plugin-babel'; |
| 3 | +import esbuild from 'esbuild'; |
| 4 | +import plugins from '@lucide/rollup-plugins'; |
| 5 | +import ts from 'typescript'; |
5 | 6 |
|
6 | 7 | import pkg from './package.json' assert { type: 'json' };
|
7 | 8 |
|
8 |
| -const config = withSolid({ |
9 |
| - targets: ['esm', 'cjs'], |
10 |
| -}); |
| 9 | +const packageName = 'LucideSolid'; |
| 10 | +const outputFileName = 'lucide-solid'; |
| 11 | +const outputDir = 'dist'; |
| 12 | +const inputs = ['src/lucide-solid.ts']; |
11 | 13 |
|
12 |
| -config.plugins = [ |
13 |
| - ...config.plugins, |
14 |
| - license({ |
15 |
| - banner: `${pkg.name} v${pkg.version} - ${pkg.license}`, |
16 |
| - }), |
17 |
| - bundleSize(), |
| 14 | +const bundles = [ |
| 15 | + { |
| 16 | + format: 'cjs', |
| 17 | + inputs, |
| 18 | + outputDir, |
| 19 | + }, |
| 20 | + { |
| 21 | + format: 'esm', |
| 22 | + inputs, |
| 23 | + outputDir, |
| 24 | + }, |
18 | 25 | ];
|
19 | 26 |
|
20 |
| -export default config; |
| 27 | +const configs = bundles |
| 28 | + .map(({ inputs, outputDir, format, preserveModules }) => |
| 29 | + inputs.map((input) => ({ |
| 30 | + input, |
| 31 | + plugins: [ |
| 32 | + babel({ |
| 33 | + extensions: ['.ts', '.tsx', '.js'], |
| 34 | + babelHelpers: 'bundled', |
| 35 | + presets: [ |
| 36 | + 'babel-preset-solid', |
| 37 | + '@babel/preset-typescript', |
| 38 | + ['@babel/preset-env', { bugfixes: true, targets: 'last 2 years' }], |
| 39 | + ], |
| 40 | + }), |
| 41 | + ...plugins({ |
| 42 | + pkg, |
| 43 | + withEsbuild: false, |
| 44 | + }), |
| 45 | + format === 'esm' |
| 46 | + ? { |
| 47 | + name: 'ts', |
| 48 | + buildEnd() { |
| 49 | + // Transpile typescript to './dist/source' |
| 50 | + esbuild.build({ |
| 51 | + entryPoints: ['./src/**/*.tsx', './src/**/*.ts'], |
| 52 | + outdir: './dist/source', |
| 53 | + loader: { |
| 54 | + '.js': 'jsx', |
| 55 | + }, |
| 56 | + jsx: 'preserve', |
| 57 | + bundle: true, |
| 58 | + format: 'esm', |
| 59 | + sourcemap: true, |
| 60 | + target: ['esnext'], |
| 61 | + banner: { |
| 62 | + js: `/** |
| 63 | +* @license ${pkg.name} v${pkg.version} - ${pkg.license} |
| 64 | +* |
| 65 | +* This source code is licensed under the ${pkg.license} license. |
| 66 | +* See the LICENSE file in the root directory of this source tree. |
| 67 | +*/`, |
| 68 | + }, |
| 69 | + plugins: [ |
| 70 | + { |
| 71 | + name: 'externalize-everything-except-own-dependencies', |
| 72 | + setup(build) { |
| 73 | + build.onResolve({ filter: /(.*)/ }, (args) => { |
| 74 | + const modulePath = path.join(args.resolveDir, args.path); |
| 75 | + if ( |
| 76 | + args.kind === 'import-statement' && |
| 77 | + args.path !== '@lucide/shared' && |
| 78 | + !modulePath.includes('packages/shared') |
| 79 | + ) { |
| 80 | + return { path: args.path, external: true }; |
| 81 | + } |
| 82 | + }); |
| 83 | + }, |
| 84 | + }, |
| 85 | + ], |
| 86 | + external: ['solid-js'], |
| 87 | + }); |
| 88 | + |
| 89 | + // Generate types |
| 90 | + const program = ts.createProgram([pkg.source], { |
| 91 | + target: ts.ScriptTarget.ESNext, |
| 92 | + module: ts.ModuleKind.ESNext, |
| 93 | + moduleResolution: ts.ModuleResolutionKind.NodeJs, |
| 94 | + jsx: ts.JsxEmit.Preserve, |
| 95 | + jsxImportSource: 'solid-js', |
| 96 | + allowSyntheticDefaultImports: true, |
| 97 | + esModuleInterop: true, |
| 98 | + declarationDir: `dist/types`, |
| 99 | + declaration: true, |
| 100 | + emitDeclarationOnly: true, |
| 101 | + }); |
| 102 | + program.emit(); |
| 103 | + }, |
| 104 | + } |
| 105 | + : null, |
| 106 | + ], |
| 107 | + external: ['solid-js', 'solid-js/web', 'solid-js/store'], |
| 108 | + output: { |
| 109 | + name: packageName, |
| 110 | + ...(preserveModules |
| 111 | + ? { |
| 112 | + dir: `${outputDir}/${format}`, |
| 113 | + exports: 'auto', |
| 114 | + } |
| 115 | + : { |
| 116 | + file: `${outputDir}/${format}/${outputFileName}.js`, |
| 117 | + }), |
| 118 | + format: format === 'source' ? 'esm' : format, |
| 119 | + preserveModules, |
| 120 | + preserveModulesRoot: 'src', |
| 121 | + sourcemap: true, |
| 122 | + }, |
| 123 | + })), |
| 124 | + ) |
| 125 | + .flat(); |
| 126 | + |
| 127 | +export default configs; |
0 commit comments