reference multiple js files in a single line in a html file

前端 未结 6 2072
时光说笑
时光说笑 2021-01-19 07:04

Is there an easy way to reference all js files in an HTML file rather than referencing it one by one?

Instead of this -



        
6条回答
  •  佛祖请我去吃肉
    2021-01-19 07:36

    There is also Gulp (http://gulpjs.com/), which can be used with various plugins. Here's an example that concatenates *.js files in one single file (main.js), then renames the resulting file and finally minifies it:

    var gulp = require('gulp'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat');
    
    gulp.task('scripts', function(){
    return gulp.src('./src/js/*.js')
    .pipe(concat('main.js'))
    .pipe(rename({suffix: '.min'}))
    .pipe(uglify())
    .pipe(gulp.dest('./src/js/*.js'));
    

提交回复
热议问题