迁移到 Pug 3(从 Pug 2)(Migrating to Pug 3 (from Pug 2))
¥Migrating to Pug 3 (from Pug 2)
如果你要从 Jade 迁移,请先按照 迁移到 Pug 2 文章进行操作。本文介绍如何从 Pug 2 升级到 Pug 3。
¥If you are migrating from Jade, please follow the Migrating to Pug 2 article first. This article covers how to upgrade from Pug 2 to Pug 3.
有关新功能的完整列表,请参阅 发行说明。以下是仅处理重大变更的说明。
¥For a complete list of new features, please refer to the release notes. What follows are instructions for dealing with breaking changes only.
带有 minify
的过滤器(filters with minify
)
¥filters with minify
注意
如果你不使用带有 “minify” 选项的过滤器,则可以忽略此更改。
¥If you are not using filters with the “minify” option, you can ignore this change.
如果你使用输出 JavaScript 或 CSS 的过滤器以及 minify
选项,则现在需要包含额外的依赖。如果你想支持缩小 JavaScript,你必须安装 jstransformer-uglify-js
,如果你想支持缩小 CSS,你必须安装 jstransformer-clean-css
。
¥If you were using filters that output JavaScript or CSS, along with the minify
option, you now need to include an extra dependency. If you want to support minifying JavaScript, you must install jstransformer-uglify-js
and if you want to support minifying CSS, you must install jstransformer-clean-css
.
read
插件现在应该返回 Buffer
(read
plugins should now return Buffer
)
¥read
plugins should now return Buffer
注意
如果你不使用插件,则可以忽略此更改。
¥If you are not using plugins, you can ignore this change.
如果你使用 read
插件来覆盖 pug 读取文件的方式,并且想要支持新的 renderBuffer
过滤器,则需要返回 Buffer
。
¥If you are using a read
plugin to override the way that pug reads files, and you want to support the new renderBuffer
filters, you will need to return Buffer
.
例如
¥e.g.
//- old
pug.renderFile(filename, {
plugins: [
{
read: (filename) => {
// this returns a "string"
return fs.readFileSync(filename, 'utf8');
},
}
]
})
//- new
pug.renderFile(filename, {
plugins: [
{
read: (filename) => {
// this returns a "Buffer"
return fs.readFileSync(filename);
},
}
]
})
Node.js 支持(Node.js Support)
¥Node.js Support
我们放弃了对 10.0.0 之前的节点版本的支持。我们建议将所有使用 pug 的项目升级到 node.js 12,但我们将在 2021 年 4 月之前支持 10。
¥We dropped support for node versions prior to 10.0.0. We recommend upgrading all projects using pug to node.js 12, but we will support 10 until April 2021.
将来,我们可能会放弃对节点版本 当他们到达生命的尽头时 的支持,而无需进行主要版本升级。
¥In future we may drop support for node versions when they reach end of life without a major version bump.