我在Gulp4中的输出文件main.min.js
遇到问题。
我认为这是串联的问题
我的路径文件:
const config = {
app: {
js: [
'./src/js/**/*.js',
],
scss: './src/sass/**/*.scss',
fonts: './src/fonts/*',
images: './src/images/*.*',
html: './src/*.html'
},
dist: {
base: './dist/',
js: './dist/js',
css: './dist/css/',
fonts: './dist/fonts',
images: './dist/images'
},
extraBundles: [
'./dist/main.js',
'./dist/main.css'
]
}
我使用这些:
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
这是我的任务:
function jsTask(done) {
src(config.app.js)
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(dest(config.dist.js))
done();
}
在index.html中,<html>
和<body>
之前的最后一行:
<script src="js/main.min.js"></script>
我看到它占用了所有js文件,但不幸的是无法正常工作。 输出文件如下:
"use strict";function RecaptchaClearMsg(){document.querySelector(".g-recaptcha").focus()}$(function(){var a={};document.querySelectorAll(".form-data").forEach(function(e){a[e.getAttribute("name")]=e});var i=document.querySelector(".g-recaptcha"),c=function(e,t){return"Pole "+e+" musi zawierać co najmniej "+t+" znaki."},l=function(e,t){return"Pole "+e+" może zawierać co najwyżej "+t+" znaków."},s=function(e){return"Pole "+e+" nie może być puste."},u=function(e){return"Pole "+e+" jest niepoprawne."},r="W formularzu występują błędy.",f="Potwierdź, że nie jesteś robotem.",n=$("#contact-form"),d=document.querySelector(".emailFormAlert");function t(e){if("boolean"!=typeof e)throw new TypeError("State must be a boolean");if(!0===e)n.fadeIn(),n.attr("aria-hidden","false"),m.focus();else{for(var t in n.fadeOut(),n.attr("aria-hidden","true"),a)a[t].value="";grecaptcha.reset(),p.focus()}}var o=$("#close-contact-btn"),p=$("#open-contact-btn");p.click(function(){t(!0)}),o.click(function(){t(!1)});var m=$(".form-data:first");function g(e,t){if(!e.classList.contains("wrongInput")){var n=document.createElement("p");n.classList.add("error"),n.classList.add("wrongInput"),n.textContent=t,e.parentElement.append(n),e.classList.add("wrongInput"),e.addEventListener("focus",h)}}function h(){this.classList.remove("wrongInput"),this.parentElement.removeChild(this.parentElement.getElementsByClassName("error")[0]),d.innerHTML=""}"#contact-form"===document.location.hash&&(p.focus(),p.click()),o.on("keydown",function(e){9!==e.which||e.shiftKey||(e.preventDefault(),m.focus())}),m.on("keydown",function(e){9===e.which&&e.shiftKey&&(e.preventDefault(),o.focus())}),n.on("keydown",function(e){27===e.which&&t(!1)}),$(".emailFormSubmit").click(function(e){if(d.innerHTML='<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>',e.preventDefault(),!0===function(){var e=!0;for(var t in a){var n=a[t].parentElement.innerText;if(!0===a[t].validity.valueMissing)g(a[t],s(n.toLowerCase()));else if(!0===a[t].validity.tooShort){var o=a[t].getAttribute("minlength");g(a[t],c(n.toLowerCase(),o))}else if(!0===a[t].validity.tooLong){var r=a[t].getAttribute("maxlength");g(a[t],l(n.toLowerCase(),r))}else!0===a[t].validity.typeMismatch&&g(a[t],u(n.toLowerCase()));!1===a[t].validity.valid&&(e=!1)}0===grecaptcha.getResponse().length&&(g(i,f),e=!1);return e}()){var t={"g-recaptcha-response":grecaptcha.getResponse()};for(var n in grecaptcha.reset(),a)t[n]=a[n].value;var o=$.ajax({type:"POST",url:document.querySelector(".emailForm").getAttribute("action"),dataType:"json",data:t});o.fail(function(e){console.log(e),d.innerHTML=r}),o.done(function(e){console.log(e),d.innerHTML="Message was sent. Thank you!"})}else d.innerHTML=r}),window.recaptchaClearErr=function(){document.querySelector(".g-recaptcha").focus()}});var myLightbox=GLightbox({selector:"glightboxTest"});$("#toggle").click(function(){$(this).toggleClass("active"),$("#overlay").toggleClass("open")});var typed=new Typed("#typing-element",{strings:['Hello, my name is Filip Handzel.<br>I graduated from Jan Matejko Academy of Fine Arts in Krakow.<br>I like programming, design, electronic and robotic art.<br> I would like to be junior front-end developer!<br><br><br>Click <a target="_blank" rel="noopener noreferrer" href="filiphandzel-cv.pdf">here</a> to download my CV'],typeSpeed:60,startDelay:1e3,loop:!1});