Next JS config multiple plugin configuration

大城市里の小女人 提交于 2020-11-29 09:50:35

问题


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
};

Here my next.config.js configuration. But when I am trying to run then getting the message like Error! Network error: Unexpected token N in JSON at position 0

But when I am trying to run whatever into the bold(*) and kept only that thing into the next.config.js then working fine. How to configure multiple plugin into the module.export


回答1:


Here is a simple way to use multiple nested plugins in Next.js

const withImages = require('next-images');
const withCSS = require('@zeit/next-css');

module.exports = withCSS(withImages({
    webpack(config, options) {
      return config
    }
  }))

If you want to using single one plugin then do this:

const withImages = require('next-images');

module.export = withImages();

For further information about Next.js plugins and their documentation click here: https://github.com/zeit/next-plugins/tree/master/packages



来源:https://stackoverflow.com/questions/54183145/next-js-config-multiple-plugin-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!