Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9330

Node.jsを使ってHTML, CSS, JavaScriptを軽量化・難読化する手順

$
0
0

はじめに

Windows環境で、Node.jsのモジュールを使って以下を行う手順をまとめます。

  • HTML, CSSの軽量化(minify)
  • JavaScriptの難読化(uglify)

使用モジュール

  • html-minifier→ HTMLファイルの軽量化モジュール
  • clean-css-cli→ CSSファイルの軽量化モジュール
  • uglify-es→ JavaScriptファイルの難読化モジュール

準備:モジュールのインストール

  1. Node.jsを取得しインストールする。→ https://nodejs.org/ja/

  2. Node.js command promptを起動する。

  3. 以下のコマンドを実行する。(2行目のプロキシ設定は必要な場合のみ実行)

$ npm -g config set registry http://registry.npmjs.org/
$ npm -g config set proxy http://xxx.xxx.xxx:8080
$ npm install -g html-minifier
$ npm install -g clean-css-cli
$ npm install -g uglify-es

使用方法

Node.js command promptから、以下のコマンドを実行する。

HTMLの軽量化

$ html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype original.html -o original.min.html

CSSの軽量化

$ cleancss -o original.min.css original.css

JavaScriptの難読化

$ uglifyjs original.js -c --compress --mangle --output original.min.js

関連記事


Viewing all articles
Browse latest Browse all 9330

Trending Articles