下一个JS配置多个插件配置

问题描述 投票:0回答:1

const {
  DEVELOPMENT_SERVER,
  PRODUCTION_BUILD
} = require("next/constants");

require('dotenv').config()

const path = require('path')
const Dotenv = require('dotenv-webpack')

const nextConfig = {
  webpack: config => ({ ...config, node: { fs: "empty" } })
};
module.exports = phase => {
  if (phase === DEVELOPMENT_SERVER || phase === PRODUCTION_BUILD) {
    const withCSS = require("@zeit/next-css");
    return withCSS(nextConfig);
  }
  return nextConfig;
};
*module.exports =  {
  webpack: (config) => {
    config.plugins = config.plugins || []
    config.plugins = [
      ...config.plugins,
      // Read the .env file
      new Dotenv({
        path: path.join(__dirname, '.env'),
        systemvars: true
      })
    ]
    return config
  }
}*

let prefix;
switch (process.env.NODE_ENV) {
  case "test":
    prefix = "https://test.domain.com/providers";
    break;
  case "stage":
    prefix = "https://state.domain.com/providers";
    break;
  case "production":
    prefix = "https://production.domain.com/providers";
    break;
  default:
    prefix = "";
    break;
}
module.exports = {
  distDir: "build",
  assetPrefix: prefix
};

这里是我的next.config.js配置。但是当我尝试运行时,会收到类似错误!网络错误:JSON位置0上的意外令牌N

但是,当我尝试将任何内容运行到粗体(*)并将其仅保留到next.config.js中时,则工作正常。如何在模块中配置多个插件。

const {DEVELOPMENT_SERVER,PRODUCTION_BUILD} = require(“ next / constants”); require('dotenv')。config()const path = require('path')const Dotenv = require('dotenv-webpack')const ...

reactjs webpack apollo next next.js
1个回答
0
投票

这是在Next.js中使用多个嵌套插件的简单方法

© www.soinside.com 2019 - 2024. All rights reserved.