Last active
September 25, 2018 06:58
-
-
Save ryonakae/66f40adc55111dcb9a03 to your computer and use it in GitHub Desktop.
Gulpで、JSファイル内で別のJSファイルをインクルードしつつ、ライセンスコメントは残してUglify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//= include ../libs/jquery.min.js | |
//= include ./_common.js | |
console.log('Hello world'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var include = require('gulp-include'); | |
var saveLicense = require('uglify-save-license'); | |
var uglify = require('gulp-uglify'); | |
gulp.task('js', function(){ | |
return gulp | |
// devのjavascriptsディレクトリ以下のJSファイルを見る | |
// ファイル名の先頭にアンダースコアがついたファイルは除外 | |
// jQueryなどのライブラリも除外 | |
.src([ | |
'./public/dev/javascripts/**/*.js', | |
'!./public/dev/javascripts/**/_*.js', | |
'!./public/dev/javascripts/libs/**/*.js' | |
]) | |
// JS内に書かれたinclude文に応じてファイルをインクルード | |
.pipe(include()) | |
// ライセンスコメントを残してUglify | |
.pipe(uglify({ | |
preserveComments: saveLicense | |
})) | |
// distにJSファイルを出力 | |
.pipe(gulp.dest('./public/dist/javascripts/')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment