Last active
May 13, 2019 18:21
-
-
Save picpoint/a91878305ff43bfbcf964fbc6b80acf0 to your computer and use it in GitHub Desktop.
Simple minify to files
This file contains 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
const fs = require('fs'); // подключаем модуль файловой системы | |
const output = fs.createWriteStream('script.min.js'); // в константу записывает исходящий поток, которая создаёт файл | |
fs.readFile('script.js', 'utf-8', function (err, data) { // читаем файл | |
if (err) { | |
throw new Error('ERROR TO READ FILE...'); // если ошибка, выбрасываем исключение | |
} else { | |
for (let i = 0; i < data.length; i++) { // пробегаемся по всем символам | |
if (data[i] != ' ' && data[i] != '' && data[i] != '\n' && data[i] != '\t') { // если не '', ' ', \n, \t | |
output.write(data[i]); // записываем каждый символ в файл | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment