V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
riccox
V2EX  ›  问与答

Nextjs 样式问题求解

  •  
  •   riccox · 2021-01-17 23:14:24 +08:00 · 703 次点击
    这是一个创建于 1710 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在使用 Nextjs + sass

    在配置 nextjs 的过程中,一直无法解决 scss 全局变量的实现以及组件间 css 模块化的实现。

    导致样式覆盖的问题,全局变量的 scss 还要每个样式文件 import 一次

    查了半天也没找到有效的解决方式

    还请大佬们指点一下(*  ̄︿ ̄)

    下面这俩都试过了。。。

    /// next.config.js
        // 全局变量和 mixin
    config.module.rules.push({
          enforce: 'pre',
          test: /.scss$/,
          loader: 'sass-resources-loader',
          options: {
              resources: ['/styles/_variables.scss'],
          }
      });
    
    /// next.config.js
    
        // css 模块化
    cssModules: true,
      cssLoaderOptions: {
          importLoaders: 1,
          // scoped class 格式
          localIdentName: "[local]__[hash:base64:5]",
      },
    
    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3321 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 04:47 · PVG 12:47 · LAX 21:47 · JFK 00:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.