Skip to content

Commit 1e7d647

Browse files
authored
Support identifier formatting configuration (#323)
1 parent 26832f1 commit 1e7d647

File tree

25 files changed

+407
-231
lines changed

25 files changed

+407
-231
lines changed

.changeset/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"access": "public",
1010
"baseBranch": "master",
1111
"updateInternalDependencies": "patch",
12+
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
13+
"onlyUpdatePeerDependentsWhenOutOfRange": true
14+
},
1215
"ignore": ["@fixtures/*", "test-helpers", "vanilla-extract-webpack-react"]
1316
}

.changeset/gold-wombats-thank.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@vanilla-extract/snowpack-plugin': major
3+
---
4+
5+
Formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can now be configured via the `identifiers` option which accepts either `short` or `debug`.
6+
7+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
8+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `somefile_mystyle_hnw5tz3`
9+
10+
```js
11+
import { vanillaExtractPlugin } from '@vanilla-extract/snowpack-plugin';
12+
13+
const snowpackConfig = {
14+
plugins: [['@vanilla-extract/snowpack-plugin', { identifiers: 'short' }]]
15+
}
16+
```
17+
18+
BREAKING CHANGE
19+
20+
Previously identifiers were formatted as `short` when `process.env.NODE_ENV` was set to "production". By default, they will now be formatted according to Snowpacks's [mode config](https://www.snowpack.dev/reference/configuration#mode).
21+

.changeset/hip-icons-destroy.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@vanilla-extract/webpack-plugin': major
3+
---
4+
5+
Formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can now be configured via the `identifiers` option which accepts either `short` or `debug`.
6+
7+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
8+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `somefile_mystyle_hnw5tz3`
9+
10+
```js
11+
import { vanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
12+
13+
vanillaExtractPlugin({ identifiers: 'short' })
14+
```
15+
16+
BREAKING CHANGE
17+
18+
Previously identifiers were formatted as `short` when `process.env.NODE_ENV` was set to "production". By default, they will now be formatted according to webpack's [mode config](https://webpack.js.org/configuration/mode/).
19+

.changeset/olive-zoos-roll.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@vanilla-extract/vite-plugin': major
3+
---
4+
5+
Formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can now be configured via the `identifiers` option which accepts either `short` or `debug`.
6+
7+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
8+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `somefile_mystyle_hnw5tz3`
9+
10+
```js
11+
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
12+
13+
vanillaExtractPlugin({ identifiers: 'short' });
14+
```
15+
16+
BREAKING CHANGE
17+
18+
Previously identifiers were formatted as `short` when `process.env.NODE_ENV` was set to "production". By default, they will now be formatted according to Vite's [mode config](https://vitejs.dev/config/#mode).

.changeset/sharp-dingos-smell.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@vanilla-extract/esbuild-plugin': major
3+
---
4+
5+
Formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can now be configured via the `identifiers` option which accepts either `short` or `debug`.
6+
7+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
8+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `somefile_mystyle_hnw5tz3`
9+
10+
```js
11+
import { vanillaExtractPlugin } from '@vanilla-extract/esbuild-plugin';
12+
13+
vanillaExtractPlugin({ identifiers: 'short' });
14+
```
15+
16+
BREAKING CHANGE
17+
18+
Previously identifiers were formatted as `short` when `process.env.NODE_ENV` was set to "production". By default, they will now be formatted according to esbuild's [minify config](https://esbuild.github.io/api/#minify).

.changeset/twenty-cougars-visit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@vanilla-extract/css': minor
3+
'@vanilla-extract/integration': minor
4+
---
5+
6+
Support configurable identifier types

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Want to work at a higher level while maximising style re-use? Check out 🍨 [S
8585
- [Snowpack](#snowpack)
8686
- [Gatsby](#gatsby)
8787
- [Test environments](#test-environments)
88+
- [Configuration](#configuration)
89+
- [identifiers](#identifiers)
8890
- [Styling API](#styling-api)
8991
- [style](#style)
9092
- [styleVariants](#stylevariants)
@@ -132,6 +134,8 @@ npm install @vanilla-extract/css @vanilla-extract/babel-plugin @vanilla-extract/
132134

133135
3. Add the [webpack](https://webpack.js.org) plugin.
134136

137+
> 💡 This plugin accepts an optional [configuration object](#configuration).
138+
135139
```js
136140
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin');
137141

@@ -185,6 +189,8 @@ npm install @vanilla-extract/css @vanilla-extract/esbuild-plugin
185189

186190
2. Add the [esbuild](https://esbuild.github.io/) plugin to your build script.
187191

192+
> 💡 This plugin accepts an optional [configuration object](#configuration).
193+
188194
```js
189195
const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');
190196

@@ -246,6 +252,8 @@ npm install @vanilla-extract/css @vanilla-extract/vite-plugin
246252

247253
2. Add the [Vite](https://vitejs.dev/) plugin to your Vite config.
248254

255+
> 💡 This plugin accepts an optional [configuration object](#configuration).
256+
249257
```js
250258
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
251259

@@ -267,6 +275,8 @@ npm install @vanilla-extract/css @vanilla-extract/snowpack-plugin
267275

268276
2. Add the [Snowpack](https://www.snowpack.dev/) plugin to your snowpack config.
269277

278+
> 💡 This plugin accepts an optional [configuration object](#configuration).
279+
270280
```js
271281
// snowpack.config.json
272282
{
@@ -305,6 +315,16 @@ In testing environments (like `jsdom`) vanilla-extract will create and insert st
305315
import '@vanilla-extract/css/disableRuntimeStyles';
306316
```
307317

318+
### Configuration
319+
320+
#### identifiers
321+
322+
Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc) can be configured by selecting from the following options:
323+
324+
- `short` identifiers are a 7+ character hash. e.g. `hnw5tz3`
325+
- `debug` identifiers contain human readable prefixes representing the owning filename and a potential rule level debug name. e.g. `myfile_mystyle_hnw5tz3`
326+
327+
Each integration will set a default value based on the configuration options passed to the bundler.
308328

309329
---
310330

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"@babel/preset-env": "^7.13.15",
4242
"@babel/preset-react": "^7.13.13",
4343
"@babel/preset-typescript": "^7.13.0",
44-
"@changesets/changelog-github": "^0.3.0",
45-
"@changesets/cli": "^2.14.1",
44+
"@changesets/changelog-github": "^0.4.0",
45+
"@changesets/cli": "^2.16.0",
4646
"@manypkg/cli": "^0.17.0",
4747
"@preconstruct/cli": "^2.0.1",
4848
"@testing-library/dom": "^7.30.0",

packages/css/src/adapter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const mockAdapter: Adapter = {
66
onEndFileScope: () => {},
77
registerComposition: () => {},
88
markCompositionUsed: () => {},
9+
getIdentOption: () => 'debug',
910
};
1011

1112
let adapter: Adapter = mockAdapter;
@@ -46,3 +47,12 @@ export const markCompositionUsed: Adapter['markCompositionUsed'] = (
4647
export const onEndFileScope: Adapter['onEndFileScope'] = (...props) => {
4748
return adapter.onEndFileScope(...props);
4849
};
50+
51+
export const getIdentOption: Adapter['getIdentOption'] = (...props) => {
52+
// Backwards compatibility with old versions of the integration package
53+
if (!('getIdentOption' in adapter)) {
54+
return process.env.NODE_ENV === 'production' ? 'short' : 'debug';
55+
}
56+
57+
return adapter.getIdentOption(...props);
58+
};

packages/css/src/identifier.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import hash from '@emotion/hash';
22

3+
import { getIdentOption } from './adapter';
34
import { getAndIncrementRefCounter, getFileScope } from './fileScope';
45

56
function getDevPrefix(debugId: string | undefined) {
@@ -29,7 +30,7 @@ export function generateIdentifier(debugId: string | undefined) {
2930

3031
let identifier = `${fileScopeHash}${refCount}`;
3132

32-
if (process.env.NODE_ENV !== 'production') {
33+
if (getIdentOption() === 'debug') {
3334
const devPrefix = getDevPrefix(debugId);
3435

3536
if (devPrefix) {

0 commit comments

Comments
 (0)