首页 > 解决方案 > 如何组合和使用多个 Next.js 插件

问题描述

我想在应用程序中使用css和。scssnext.js

next.config.js在我的项目中有。

此配置适用于scss

// next.config.js
const withSass = require('@zeit/next-sass');

module.exports = withSass({
    cssModules: true,
    cssLoaderOptions: {
        importLoaders: 1,
        localIdentName: "[local]___[hash:base64:5]",
    }
})

我不知道如何const withCSS = require('@zeit/next-css');与我当前的配置相结合。

我想使用自定义配置scss(来自我的代码片段)。

有人可以帮我配置下一个cssscss模块吗?

我试过了:

// // next.config.js
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');

module.exports = withCSS(withSass({
    cssModules: true,
    cssLoaderOptions: {
        importLoaders: 1,
        localIdentName: "[local]___[hash:base64:5]",
    }
}))

不工作...

标签: cssreactjssassnext.js

解决方案


您可以使用next-compose-plugins和组合多个 next.js 插件,如下所示:

// next.config.js
const withPlugins = require('next-compose-plugins');
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');

module.exports = withPlugins(
  [
    [withSass, { /* plugin config here ... */ }],
    [withCSS,  { /* plugin config here ... */ }],
  ],
  {
    /* global config here ... */
  },
);

推荐阅读