elishd
elishd

Reputation: 103

How to do a Next.js Build and Export WIthout Minification and Optimization

How can I do a Next.js build and export without minifying and optimizing the output files?

Upvotes: 10

Views: 15057

Answers (3)

Trevor Robinson
Trevor Robinson

Reputation: 16564

Here's a version of @matt-jensen's answer with Typescript types:

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  // ...
  /**
   * @param {import('webpack').Configuration} webpackConfig
   * @returns {import('webpack').Configuration}
   */
  webpack(webpackConfig) {
    return {
      ...webpackConfig,
      optimization: {
        minimize: false,
      },
    };
  },
};

module.exports = nextConfig;

Upvotes: 2

Matt Jensen
Matt Jensen

Reputation: 1564

next.config.js

module.exports = (nextConfig) => {
  return {
    ...nextConfig,
    webpack(webpackConfig) {
      return {
        ...webpackConfig,
        optimization: {
          minimize: false
        }
      };
    }
  };
};

Using next@^12.0.0 will produce unminified HTML, JS, and somewhat CSS.

Upvotes: 11

Ryan Le
Ryan Le

Reputation: 8412

For compression, you would open your next.config.js and set it to false:

module.exports = {
  compress: false,
}

And for minify, you would do it in your webpack.config.js:

module.exports = {
  //...
  optimization: {
    minimize: false,
  },
};

Upvotes: 12

Related Questions