-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('.', '-')}`; | ||
} | ||
}) | ||
] | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters