【发布时间】:2021-10-09 15:41:19
【问题描述】:
我正在开发一个使用 node-sass 编译 SCSS 的应用程序。我的组件结构是这样的:
./src
|-- components
| |-- Foo
| | |-- Foo.jsx
| | `-- Foo.scss
| |-- Bar
| |-- Bar.jsx
| `-- Bar.scss
[...]
然后我这样称呼我的 scss:
import React, {useState} from 'react';
import './Foo.scss';
[...]
当我运行开发构建时,我的所有转换都正常,但是当我运行构建和部署时,它们会丢失。所有其他 CSS 样式都可以正常工作,只是我的转换搞砸了。它们仍然存在,但它们都发生在最后一帧。因此,如果一个转换应该在 200 毫秒内从 0 变为 100,它仍然会发生,但它会在最后一个可能的帧中从 0 变为 100。
谁能指出我正确的方向?这是我的 package.json:
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"node-sass": "^4.14.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-map-gl": "^5.2.7",
"react-map-gl-geocoder": "^2.0.12",
"react-redux": "^7.2.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^3.4.3",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
编辑:根据要求,这是我的转换示例:
.fade-in {
animation: fade-in ease-in 0.25s,
slide-in ease-in 0.25s;
}
@keyframes fade-in {
0% {
opacity: 0%;
}
100% {
opacity: 100%;
}
}
@keyframes slide-in {
0%{
transform: translateY(50px);
}
100%{
transform: translateY(0px);
}
}
然后我根据状态有条件地添加类。
【问题讨论】:
-
向我们展示您的转换?
-
谢谢,刚刚编辑了帖子并添加了一个过渡。
-
ease-in是否被正确转换为最终的 CSS?如果将ease-in都替换为它们的显式形式cubic-bezier(0.42, 0.0, 1.0, 1.0),会发生什么情况 -
如果在每个
0%{}关键帧中添加animation-timing-function: ease-in;会发生什么? -
@JohnFajardo 你能解决它吗?我面临同样的问题。在开发版本中工作,而不是在生产版本中工作。
标签: javascript reactjs webpack sass create-react-app