缩小/优化 NextJS 站点

Jor*_*llo 3 reactjs webpack babeljs next.js

我有一个 nextjs 网站。

我的 common.js 和我的 custom.scss 不会被 next 缩小。

我在 next.config.js 中尝试了下一个:

const withSass = require('@zeit/next-sass')
const withOptimizedImages = require('next-optimized-images');
const withTypescript = require('@zeit/next-typescript')
module.exports = withSass({minified:true},withOptimizedImages(withTypescript()))
Run Code Online (Sandbox Code Playgroud)

我的 .babelrc

{
    "presets": [
        "next/babel",
        "@zeit/next-typescript/babel",
        "minify"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的 tsconfig.json

{
    "compilerOptions": {
        "allowJs": true,
        "allowSyntheticDefaultImports": true,
        "jsx": "preserve",
        "lib": [
            "dom",
            "es2017"
        ],
        "module": "esnext",
        "moduleResolution": "node",
        "noEmit": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "preserveConstEnums": true,
        "removeComments": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true,
        "target": "esnext"
    }
}
Run Code Online (Sandbox Code Playgroud)

它应该工作还是我必须实施更多的东西?

小智 5

我的 next.config.js:

const withCSS = require("@zeit/next-css");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

module.exports = 
    withCSS({
      webpack(config, options) {
         config.optimization.minimizer = [];
         config.optimization.minimizer.push(new OptimizeCSSAssetsPlugin({}));

      return config;
     }
   });
Run Code Online (Sandbox Code Playgroud)


fel*_*osh 3

缩小版本仅在模式下创建production,因为缩小代码需要时间。

为了缩小你的生产模式,你应该在运行时设置NODE_ENV生产next build

您可以通过将 npm 构建脚本更改为: 来完成它NODE_ENV=production next build