Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(VanillaExtract): Use custom identifier generation #1299

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ import react from '@vitejs/plugin-react';
import {vanillaExtractPlugin} from '@vanilla-extract/vite-plugin';
import noBundlePlugin from 'vite-plugin-no-bundle';
import preserveDirectivesPlugin from 'rollup-plugin-preserve-directives';
import {version as packageVersion} from './package.json';

/**
* Identifiers must start with a letter (not number) and can't contain dots
* Removing trailing zeros to reduce the size of the identifier
*
* 1.2.3 => v1_2_3
* 1.2.0 => v1_2
* 1.0.0 => v1
*/
const version = 'v' + packageVersion.replace(/(\.0)*$/, '').replace(/\./g, '_');

export default defineConfig({
plugins: [
react(),
vanillaExtractPlugin(),
vanillaExtractPlugin({
identifiers: ({hash}) => `${version}_${hash}`,
Copy link
Member Author

@pladaria pladaria Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another idea, to create shorter identifier names:

Create a map hash=>autoincrementCounter

and the resulting identifiers would be: v{version}_i{counter}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that approach would work. If vite uses multiple processes to compile files, you'd have collisions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, leaving this as is

}),
noBundlePlugin({
// Change .css.js files to something else so that they don't get re-processed by consumer apps using vanilla extract too
fileNames: ({name}) => `${name.replace(/\.css$/, '.css-mistica')}.js`,
Expand Down
Loading