Comments (3)
from art-template.
也遇到了这个问题,已解决
// 确保 NODE_ENV 为 production
// Ensure that NODE_ENV is set to production,
process.env.NODE_ENV = "production";
const artTemplate = require("art-template");
const htmlMinifier = require("html-minifier");
const htmlString = `
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{title}}!</title>
<style>
body {
padding: 20px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
color: #333;
}
</style>
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">{{ message }}</h1>
<p class="subtitle">My first website with <strong>Art-Template</strong>!</p>
<p class="subtitle">{{ now }}</p>
</div>
</section>
</body>
</html>
`;
const data = {
title: "Hello, World",
message: "你好,世界",
now: +new Date(),
};
// 默认配置即可启用压缩(NODE_ENV === "production")
// By default, the compression is enabled(NODE_ENV === "production")
const options1 = {};
const res1 = artTemplate.render(htmlString, data, options1);
console.log(`Res1: ${res1}`);
const options2 = {
debug: false,
// 不要这样,因为art-template内部对htmlMinifier做了处理
// Do not do this, because art-template internally processes htmlMinifier
htmlMinifier: htmlMinifier.minify,
};
const res2 = artTemplate.render(htmlString, data, options2);
console.log(`Res2: ${res2}`); // 不会被压缩 (It will not be compressed)
// 如果确实需要自定义压缩器,这样整
// If you really need to customize the compression, do this
const options3 = {
htmlMinifier: htmlMinifier.minify,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
ignoreCustomFragments: [],
};
const res3 = artTemplate.render(htmlString, data, options3);
console.log(`Res3: ${res3}`); // ✔
// 具体原因看源码,也许后面会写出来分享到博客,咕咕咕咕咕
// For more details, see the source code, which may be shared to the blog
from art-template.
from art-template.
Related Issues (20)
- windows 下运行 webpack 5,使用 art-template-loader 路径解析出现错误 HOT 4
- 请问遍历对象的原始语法是怎么写?
- 标准语法 if 多条件编译报错 HOT 1
- Help. 请教 vue2 项目中 如何 使用 cdn 引入 art-template 并使用?
- 对deno的支持
- react项目通过 import artTemplate from "art-template" 引入异常 HOT 4
- 渲染的数据是多行,会导致错误 HOT 1
- 在 js 中配置模板,能使用 include 吗?
- 如何使用Arttemplate在页面上遍历一个数字?
- {{@@item.value}} 在{{each }}中无效
- art-template native v3.0.0 360 IE6内核版本显示模板源码
- 异步自定义filter?
- 模板解析后占位符不准确 HOT 2
- Webpack loader, syntax include with parameter looks doesn't work. HOT 2
- 请问可以在nestJS中配置art-template吗? HOT 1
- 该如何将类中的 this 传入 $data 里呢 HOT 2
- Doesn't work with bun.js because require.extensions[template.defaults.extname] = extension; looks like it's not supported HOT 2
- 能出个serviceWorker版本吗? HOT 1
- 如何插值为html标签的属性,而不仅是插值为内容? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from art-template.