使用 Next.js 和 TypeScript 开发页面构建时间很慢 [英] Slow page build time in development with Next.js and TypeScript

查看:367
本文介绍了使用 Next.js 和 TypeScript 开发页面构建时间很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目中使用 next.js 创建一个具有后端和前端的网站.在生产中,加载网页需要很多时间.下一版本是 9.3.0.这是我的脚本.使用 scss 效果加载时间

Created a website using next.js with both backend and frontend in one project.In production it takes so much of time to load a webpage.Next version is 9.3.0. this is my script.using of scss effects loading time

package.json

package.json

"scripts": {
    "dev": "ts-node --compiler-options=\"{\\\"module\\\": \\\"commonjs\\\"}\" server/server.ts",
    "build": "next build",
    "start": "NODE_ENV=production 'ts-node' --compiler-options=\"{\\\"module\\\": \\\"commonjs\\\"}\" server/server.ts"
}

推荐答案

我猜您正在使用 npm run start 启动您的生产应用程序.从它来看,您似乎在 production(即时编译 TS)上运行 ts-node.

I guess that you are starting your production app using npm run start. From it, it looks like you are running ts-node on production (which compiles TS on the fly).

最好在 build 步骤上使用 typescript into dist 或类似的东西compile server.ts,然后在 dist 文件夹中的 js 结果上运行 node.

It is better to compile server.ts on build step using typescript into dist or something like this, then run node on a js result inside dist folder.

这篇关于使用 Next.js 和 TypeScript 开发页面构建时间很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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