缩小/优化NextJS网站 [英] Minify / Optimize NextJS site

查看:53
本文介绍了缩小/优化NextJS网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个nextjs网站.

I have a nextjs site.

下一步不会缩小我的common.js和custom.scss.

My common.js and my custom.scss don't be minified by next.

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

I tried the next one in 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()))

我的.babelrc

My .babelrc

{
    "presets": [
        "next/babel",
        "@zeit/next-typescript/babel",
        "minify"
    ]
}

我的tsconfig.json

My 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"
    }
}

它应该可以工作,或者我还需要执行更多操作?

It should work or i have to implement some thing more?

推荐答案

我的next.config.js:

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

这篇关于缩小/优化NextJS网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆