Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next JS config multiple plugin configuration

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

like image 835
SKP Avatar asked Jan 14 '19 14:01

SKP


1 Answers

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

like image 97
naeem1098 Avatar answered Oct 27 '22 20:10

naeem1098