LoginSignup
2
3

More than 5 years have passed since last update.

gulp-uglifyでJavaScriptを圧縮する (CentOS 7)

Posted at

環境

$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

インストール

$ sudo yum install npm
$ sudo npm install gulp -g
$ echo '{}' > package.json
$ npm install gulp --save-dev
$ npm install gulp-uglify --save-dev
$ gulp -v
[22:10:40] CLI version 3.9.1

設定ファイル記述

gulpfile.jsというファイルを作って下記記述

gulpfile.js
var gulp = require("gulp");
var uglify = require('gulp-uglify');

var src = './source';
var dst = './destination';

gulp.task('default', function(){
  gulp.src(src+'/*.js')
    .pipe(uglify())
    .pipe(gulp.dest(dst));
});

実行

非圧縮ファイルを./source配下に配置

source/sample.js
var hogehogefugafuga = 12345//67890
console.log(hogehogefugafuga);

圧縮

$ gulp
[22:25:26] Using gulpfile ~/gulpfile.js
[22:25:26] Starting 'default'...
--------- uglify task ----------
[22:25:26] Finished 'default' after 14 ms

./destination配下で結果を確認

destination/sample.js
var hogehogefugafuga=12345;console.log(hogehogefugafuga);

参考

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3