【问题标题】:Add css loader to next.config.js将 css 加载器添加到 next.config.js
【发布时间】:2020-12-01 14:04:12
【问题描述】:

目前我有这个next.config.js:

const withCSS = require('@zeit/next-css')
const withLess = require('@zeit/next-less')
const withSass = require('@zeit/next-sass')

if (typeof require !== 'undefined') {
  require.extensions['.less'] = () => {}
}

module.exports = withCSS(
  withLess(
    withSass({
      lessLoaderOptions: {
        javascriptEnabled: true,
      },
    })
  )
)

我正在尝试使用 react-rce,但在 the docs 中,他们说我需要将 style-loader 添加到我的 webpack 配置中。

例如

 module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },

但我不明白如何将它添加到我当前的文件中。有什么想法吗?

谢谢

【问题讨论】:

    标签: webpack next.js webpack-style-loader


    【解决方案1】:

    您可以像这样在文件中为 css-loader 添加额外的模块规则:

    const withCSS = require('@zeit/next-css')
    const withLess = require('@zeit/next-less')
    const withSass = require('@zeit/next-sass')
    
    if (typeof require !== 'undefined') {
      require.extensions['.less'] = () => {}
    }
    
    module.exports = withCSS(
      withLess(
        withSass({
          lessLoaderOptions: {
            javascriptEnabled: true,
          },
          webpack: config => {
            config.module.rules.push(
              {
                test: /\.css$/i,
                use: ['style-loader', 'css-loader'],
              }
            );
            return config;
          }
        })
      )
    )
    

    【讨论】:

    • 谢谢!我必须在底部添加一个return config
    • 哎呀,我忘了说,会更新我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 2021-06-26
    • 2019-04-01
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 2019-07-06
    相关资源
    最近更新 更多