- 确保本地和Netlify环境中使用的是相同的Vanilla Extract版本。
- 在本地运行时,确保在组件中使用的类名与样式表中定义的类名一致。
- 在Netlify中使用预处理器(如PostCSS)时,确保正确配置了类名的哈希生成方法。
例如,可以使用以下代码将类名与哈希联系起来:
// styles.css
:vars {
color-primary: #007aff;
}
.button {
background: var(color-primary);
}
// styles.css.ts
import { createVar, style } from '@vanilla-extract/css';
export const colorPrimary = createVar();
export const button = style({
background: colorPrimary,
});
// classnames.css
.button-df89e2 {
background: #007aff;
}
// index.js
import classnames from './classnames.css';
import { button } from './styles.css';
const App = () => {
return (
Hello World!
);
}
export default App;