withPlugins(next.config.js)

ws00·2021년 7월 2일

여러개의 plugin을 사용시 next-compose-plugins를 사용하면 쉽게 적용이 가능하다.

next-compose-plugin npm : https://www.npmjs.com/package/next-compose-plugins

설치: npm i next-compose-plugins

사용방법
module.exports = withPlugins([plugin1, plugin2, ...], {
  webpack(config, {webpack}){
    return {
      ...config
    }
  }
});
예시
const withPlugins = require('next-compose-plugins');
const withImages = require('next-images');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});

module.exports = withPlugins([withBundleAnalyzer, withImages], {
  compress: true,
  webpack(config, { webpack }) {
    const prod = process.env.NODE_ENV === 'production';
    return {
      ...config,
      mode: prod ? 'production' : 'development',
    };
  },
});

0개의 댓글