create-react-app CSS构建错误

vwkv1x7d  于 2个月前  发布在  React
关注(0)|答案(5)|浏览(41)

在App.css中,我添加了以下代码。

:root {
  --distance: 44px;
}

div {margin-top: calc(var(--distance)*-1/2);}

之后,运行npm run build

kxeu7u2r

kxeu7u2r1#

{
// Options for PostCSS as we reference these options twice
// Adds vendor prefixing based on your specified browser support in
// package.json
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebook/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 4,
}),
// Adds PostCSS Normalize as the reset css with default options,
// so that it honors browserslist config in package.json
// which in turn let's users customize the target behavior as per their needs.
postcssNormalize(),
],
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
},
},


这样,项目就可以成功构建了~
ifmq2ha2

ifmq2ha22#

阶段4或5都很好!

vlf7wbxs

vlf7wbxs3#

@iansu@mrmckeb@ianschmitz@petetnt 你觉得有必要更新吗?

z9smfwbn

z9smfwbn4#

我认为最好的方法是将postcss-custom-properties升级到9.1.1~版本。

ffx8fchx

ffx8fchx5#

但是有时候也需要以下的写作方法,

:root {
 --distance: 20px + 20px;
}

或者

calc(var(--distance)*-1/2)

此外,底层解析器 postcss-values-parser 也支持这种方法~你可以查看这个问题 postcss/postcss-custom-properties#161

相关问题