Skip to content

Commit

Permalink
update rolldown config
Browse files Browse the repository at this point in the history
  • Loading branch information
nstepien committed Dec 22, 2024
1 parent 9b4fe3a commit d03f789
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"rolldown": "^0.15.1",
"rollup-plugin-postcss": "^4.0.2",
"typescript": "~5.7.2",
"vite": "^6.0.3",
"vitest": "^2.1.8",
Expand Down
79 changes: 46 additions & 33 deletions rolldown.config.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
// @ts-check
import { isAbsolute } from 'node:path';
import wyw from '@wyw-in-js/rollup';
import postcss from 'rollup-plugin-postcss';
import pkg from './package.json' with { type: 'json' };
import { defineConfig } from 'rolldown';

const annotationRegexp = /^[@#]__.+__$/;
// TODO: can't preserve minifier annotations, open issue
// const annotationRegexp = /^[@#]__.+__$/;

export default defineConfig({
input: './src/index.ts',
output: [
{
file: './lib/bundle.js',
format: 'es',
generatedCode: 'es2015',
sourcemap: true
},
{
file: './lib/bundle.cjs',
format: 'cjs',
generatedCode: 'es2015',
sourcemap: true
}
],
external: (id) => !id.startsWith('.') && !id.startsWith('@linaria:') && !isAbsolute(id),
plugins: [
wyw({
preprocessor: 'none',
classNameSlug(hash) {
// We add the package version as suffix to avoid style conflicts
// between multiple versions of RDG on the same page.
return `${hash}${pkg.version.replaceAll('.', '-')}`;
}
}),
postcss({
extract: 'styles.css'
})
]
});
/**
* @type {readonly import('rolldown').OutputOptions[]}
*/
const outputs = [
{
dir: 'lib',
entryFileNames: 'bundle.js',
cssEntryFileNames: 'styles.css',
format: 'es',
sourcemap: true,
comments: 'preserve-legal'
},
{
dir: 'lib',
entryFileNames: 'bundle.cjs',
cssEntryFileNames: 'styles.css',
format: 'cjs',
sourcemap: true
}
];

export default outputs.map((output) =>
defineConfig({
input: './src/index.ts',
output,
platform: 'browser',
external: (id) => !id.startsWith('.') && !isAbsolute(id),
plugins: [
// @ts-expect-error
wyw({
preprocessor: 'none',
/**
* @param {string} hash
*/
classNameSlug(hash) {
// We add the package version as suffix to avoid style conflicts
// between multiple versions of RDG on the same page.
return `${hash}${pkg.version.replaceAll('.', '-')}`;
}
})
]
})
);
3 changes: 2 additions & 1 deletion tsconfig.js.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"allowJs": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["**/*.js", ".github/**/*.js"],
"include": ["**/*.js", ".github/**/*.js", "package.json"],
"exclude": ["./coverage/**/*", "./dist/**/*", "./lib/**/*"]
}

0 comments on commit d03f789

Please sign in to comment.