NextJS配置文件模块导出设置

时间:2020-06-02 17:50:09

标签: javascript reactjs next.js

我已经研究了其他答案,即将多个插件添加到next.js配置fil的方法是使用组合。但是,这对我不起作用。

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: 'https://X.com/products/poster'");
header("Access-Control-Allow-Origin: 'https://X.com/'");
header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization; x-pf-language');
header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');

当我尝试将SCSS文件导入到组件中时,以上操作会引发错误。

但是只有

const Dotenv = require('dotenv-webpack');
const withStyles = require('@webdeb/next-styles');


module.exports = withStyles(
  {
    webpack(config, options) {
      config.plugins.push(new Dotenv({ silent: true }));
      return config;
    },
    env: {
      NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST,
      AUTH_SECRET: process.env.AUTH_SECRET,
    },
  },
  {
    sass: true, // use .scss files
    modules: true, // style.(m|module).css & style.(m|module).scss for module files
  },
);

工作正常并正确加载我的CSS

1 个答案:

答案 0 :(得分:1)

withStyles仅接受1个对象,在非工作配置中,您只有2个对象。您需要类似以下内容的

const Dotenv = require('dotenv-webpack');
const withStyles = require('@webdeb/next-styles');


module.exports = withStyles(
  {
    webpack(config, options) {
      config.plugins.push(new Dotenv({ silent: true }));
      return config;
    },
    env: {
      NEXT_PUBLIC_BACKEND_HOST: process.env.NEXT_PUBLIC_BACKEND_HOST,
      AUTH_SECRET: process.env.AUTH_SECRET,
    },
    sass: true, // use .scss files
    modules: true, // style.(m|module).css & style.(m|module).scss for module files
  },
);