Sass

前端之旅——工程化篇

旧城冷巷雨未停 提交于 2021-01-08 01:13:11
“我们活得好好的,为什么要工程化?” 让我们从原始的前端开始。用记事本新建一个卡哇伊的a.html页面,给它点样式a.css,DUANG加特技a.js。无须编译,本地预览,OK,没问题,上传服务器,等用户访问。哇,前端好好玩,好简单有木有?!然后,我们访问页面,效果还行,再看下网络请求,200!完美! 等一下,还没完呢?小公司到这儿就OK了,数据上上去,没兼容问题,完美啊!大公司说:注意性能,我要访问量!不好玩了吧!看看a.css的请求,如果每次用户访问都要加载,是不是很影响性能,浪费宽带啊!如果网络请求状态是304就好了!304,本地缓存! 这回成了吗?不行,304是协商缓存,还是要和服务器通信一次。于是必须彻底灭掉这个请求,那么强制使用本地缓存,不要和服务器通信。那么问题来了:都不让浏览器发资源请求了,这缓存还咋更新呢?对,更新页面中引用的资源路径,让浏览器放弃缓存,加载新资源。问题解决,完美! 大兄弟,别慌呀!现在a.html上面只有一个a.css,带上版本参数来改变资源路径,OK。假如还有b.css、c.css,某次上线只改了a.css的版本,通用的路径生成器上将全部版本都改了,那岂不是又有浪费了。这样一来,要解决这种问题就必须让版本修改和文件内容关联,才能准确地对应资源版本。什么东西与文件内容相关呢?大佬们想到利用数据摘要算法对文件求摘要信息

Module parse failed: Unexpected character '@' (1:0) with Storybook 6.1.11, Webpack 5.11.0, React 17.0.1

丶灬走出姿态 提交于 2021-01-06 03:40:58
问题 Trying to setup a react-app with all latest versions. Github Repo Link Trying to run storybook with sass file imported will result in below error. Trying to run without importing the styles, storybook works. The same code works correctly when its run as npm start run with no warnings and errors. I have configured css modules using @dr.pogodin/babel-plugin-react-css-modules with sass, webpack 5, react 17 and with latest packages. ERROR in ./src/assets/stylesheets/app.scss 1:0 Module parse

Using webpack to prepend variables for SCSS

一个人想着一个人 提交于 2021-01-02 06:55:07
问题 Webpack amateur here... I'm trying to incorporate a theme.scss file to customize the theme used by React Toolbox by following the directions specified here, namely: If you are using Webpack as module bundler, you are probably using sass-loader as well. What we want to do is to prepend to each SASS file compilation a bunch of variables to override and this can be done with the data option. For example: sassLoader: { data: '@import "' + path.resolve(__dirname, 'theme/_theme.scss') + '";' } In

what is font-display CSS feature?

烈酒焚心 提交于 2021-01-02 05:13:25
问题 For my website, I am getting following feedback from Google's PageSpeed Insights: Leverage the font-display CSS feature to ensure text is user-visible while web fonts are loading. What does that mean? 回答1: CSS font-display allows you to control how web fonts are swapped with system fonts while/after they load. Lighthouse is telling you that you're loading a large amount of font data using @font-face so there will be lag (up to several seconds) where your content is blank while waiting for the

NextJS component level SASS styling

。_饼干妹妹 提交于 2021-01-01 04:12:57
问题 I am working on a simple NextJS app, but I am having trouble with component level styling using SASS/SCSS. Everything looks fine when the user first lands on the page, but when the user navigates to a page /about for example or from /about to / , the component styles didn't get render, the user needs to refresh the page to see the styles 🤔 ⚙️ SETTINGS ./package.json "dependencies": { "@zeit/next-css": "1.0.1", "@zeit/next-sass": "1.0.1", "autoprefixer": "^9.7.0", "next": "^9.3.1", "node-sass"

NextJS component level SASS styling

白昼怎懂夜的黑 提交于 2021-01-01 04:12:18
问题 I am working on a simple NextJS app, but I am having trouble with component level styling using SASS/SCSS. Everything looks fine when the user first lands on the page, but when the user navigates to a page /about for example or from /about to / , the component styles didn't get render, the user needs to refresh the page to see the styles 🤔 ⚙️ SETTINGS ./package.json "dependencies": { "@zeit/next-css": "1.0.1", "@zeit/next-sass": "1.0.1", "autoprefixer": "^9.7.0", "next": "^9.3.1", "node-sass"

NextJS component level SASS styling

眉间皱痕 提交于 2021-01-01 04:10:41
问题 I am working on a simple NextJS app, but I am having trouble with component level styling using SASS/SCSS. Everything looks fine when the user first lands on the page, but when the user navigates to a page /about for example or from /about to / , the component styles didn't get render, the user needs to refresh the page to see the styles 🤔 ⚙️ SETTINGS ./package.json "dependencies": { "@zeit/next-css": "1.0.1", "@zeit/next-sass": "1.0.1", "autoprefixer": "^9.7.0", "next": "^9.3.1", "node-sass"

NextJS component level SASS styling

夙愿已清 提交于 2021-01-01 04:10:21
问题 I am working on a simple NextJS app, but I am having trouble with component level styling using SASS/SCSS. Everything looks fine when the user first lands on the page, but when the user navigates to a page /about for example or from /about to / , the component styles didn't get render, the user needs to refresh the page to see the styles 🤔 ⚙️ SETTINGS ./package.json "dependencies": { "@zeit/next-css": "1.0.1", "@zeit/next-sass": "1.0.1", "autoprefixer": "^9.7.0", "next": "^9.3.1", "node-sass"

Import all sass file within directory with webpack

限于喜欢 提交于 2020-12-29 12:32:44
问题 I'm currently trying to use Webpack to bundle all my files and I don't know how to proceed when dealing with multiple folders and .scss files. I used to use grunt to do these tasks, and this is an example of my folder structure: functions - _mixin.scss - _function.scss - [...] variables - _colors.scss - _typo.scss - [...] ui - _button.scss - _grid.scss - [...] view - _home.scss - _about.scss - [...] With Grunt I would run a task to generate a file called main.scss containing all the @import ,