gpt4 book ai didi

javascript - 为什么 html-minifier 告诉我 : Unknown option `--minifyJS' ?

转载 作者:行者123 更新时间:2023-11-30 15:19:14 25 4
gpt4 key购买 nike

问题:

我在全局安装了 uglify-js 并安装了 html-minifier

HTML 的缩小工作正常,但是当我添加 --minifyJS 来缩小 javascript 时,它失败并出现以下错误:

  error: unknown option `--minifyJS'

我做错了什么?


代码:

html-minifier --input-dir ./viewsCopy --output-dir ./views-minified --collapse-whitespace --html5 --minifyJS

引用:

https://www.npmjs.com/package/html-minifier


输出

<% include ../partials/header %> <div class="backgroundLogin"><div class="alertMessage"> <% if (errors.length > 0) { for (var i = 0; i < errors.length; i++) {%> <div class="alert alert-danger"> <%= errors[i].msg %> </div> <% } }%> </div><div class="alertMessage"><span class="alert alert-success containerMargins" id="successDiv"></span> <span class="alert alert-danger containerMargins" id="errorDiv"></span></div><div class="alertMessage"> <% if (success_msg != false){ %> <span class="alert alert-success containerMargins"> <%= success_msg %> </span> <% } %> <% if (error_msg != false){ %> <span class="alert alert-danger containerMargins"> <%= error_msg %> </span> <% } %> </div><div class="containerMargins"><h1 class="authTitle">Login</h1><form id="loginForm"><div class="form-group"><label>Email</label><input type="email" class="form-control" name="email" id="loginEmail" placeholder="You can't forget it :)" required></div><div class="form-group"><label>Password</label><input type="password" class="form-control" name="password" id="loginPassword" placeholder="We hope you didn't forget it ^^" required minlength="12"></div><div class="g-recaptcha" data-sitekey="6LcRrxMUAAAAANx-AXSdRLAo4Pyqfqg-1vuPSJ5c"></div><button class="btn btn-default" id="loginButton">Submit</button> <span class="userLinks"><a class="logLinks" href="/users/register">Register</a><a href="/users/password">Password?</a></span></form></div></div> <% include ../partials/indexScripts %> <script>$("#loginForm").submit(function(e) {

e.preventDefault();
var email = $("#loginEmail").val();
var password = $("#loginPassword").val();

$this = $(this);
$.ajax({
type: "POST",
url: "login",
data: $this.serialize()
}).done(function(data) {

if (data == true) {

firebase.auth().signInWithEmailAndPassword(email, password ).then( authData => {

var pendingRef = firebase.database().ref('pending/'+authData.uid.toString());
var userRef =firebase.database().ref('users/'+authData.uid.toString());

pendingRef.once('value', function(snapshot){

if(snapshot.val() == null) {

localStorage.setItem("success_msg_local2", "You have logged in");
("Success1 ");
window.location.href="/fun/index";

} else {
if (authData.emailVerified) {

userRef.set(snapshot.val());
pendingRef.remove();

localStorage.setItem('success_msg_local2', 'You have logged in');
("Success2");

window.location.href="/fun/index";
}

else {

firebase.auth().signOut().then(function() {
localStorage.setItem('error_msg_local', 'Please confirm your email address. Check your inbox.');
window.location.href="/users/login";
("Login Failed: ", error);

}, function(error) {

});
}

}
});

},function(error) {

var errorCode = error.code;
var errorMessage = error.message;
localStorage.setItem('error_msg_local', "Unknown user or password");
window.location.href="/users/login";
("Login Failed: ", errorMessage, errorCode);

});
}
else {
localStorage.setItem('error_msg_local', 'Recaptcha failed'); window.location.href = "/users/login";
}
});
});</script>

最佳答案

查看文档后发现命令应该是 --minifyJS,但是,我快速查看了 --help 页面 html-minifier 表示如下;

--minify-js [value] Minify Javascript in script elements and on* attributes (uses uglify-js)

[value] 应设置为 true

所以你的最终命令应该是

html-minifier --input-dir ./viewsCopy --output-dir ./views-minified --collapse-whitespace --html5 --minify-js true

如果是 HTML 文件的一部分,这似乎不会压缩 jQuery,因此将 javascript 放在外部文件中可能是有益的,或者替代的压缩器可能能够实现您想要的。

关于javascript - 为什么 html-minifier 告诉我 : Unknown option `--minifyJS' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44000594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com