问题:
我在全局安装了uglify-js
,我安装了html-minifier
。
缩小HTML工作正常但是当我添加--minifyJS
以缩小javascript时,它会失败并出现以下错误:
error: unknown option `--minifyJS'
我做错了什么?
CODE:
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>
答案 0 :(得分:2)
看一下文档,看起来该命令应该是--minifyJS
,但是,我快速查看--help
的{{1}}页面,它表示以下内容;
html-minifier
--minify-js [value] Minify Javascript in script elements and on* attributes (uses uglify-js)
应设置为[value]
。
Sor你的最终命令应该是
true
如果HTML文件的一部分出现,则不会压缩jQuery,因此将javascript放在外部文件中可能是有益的,或者替代缩小器可能能够实现您想要的效果。