導航:首頁 > 文件處理 > nodejs打包壓縮

nodejs打包壓縮

發布時間:2022-07-11 04:09:38

❶ 如何使用nodejs 的 uglifyjs 壓縮js文件

[js壓縮]uglifyjs source.js -mc -o target.min.js
以壓縮angular.js為例,可以壓縮局部變數名,去掉無用的局部變數,空白符等,壓縮比例接近80%,效率不錯
[user_00@localhost ~]$ uglifyjs angular.js -mc -o angular.min.js
WARN: Dropping unused function isBoolean [angular.js:416,9]
WARN: Dropping unused function makeMap [angular.js:446,9]
WARN: Dropping unused function size [angular.js:488,9]
WARN: Dropping unused function isLeafNode [angular.js:523,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4682,27]
WARN: Dropping unused function argument rootElement [angular.js:4681,16]
WARN: Dropping unused function argument nodeList [angular.js:4680,17]
WARN: Dropping unused function argument scope [angular.js:4679,22]
WARN: Dropping unused function nodesetLinkingFn [angular.js:4678,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4690,27]
WARN: Dropping unused function argument rootElement [angular.js:4689,16]
WARN: Dropping unused function argument node [angular.js:4688,13]
WARN: Dropping unused function argument scope [angular.js:4687,22]
WARN: Dropping unused function argument nodesetLinkingFn [angular.js:4686,25]
WARN: Dropping unused function directiveLinkingFn [angular.js:4685,9]
WARN: Dropping unused function stripHash [angular.js:5009,9]
WARN: Dropping unused variable NG_SWITCH [angular.js:13857,4]
WARN: Dropping unused variable fns [angular.js:1536,8]
WARN: Dropping unused variable events [angular.js:1536,13]
WARN: Dropping unused function wrongMode [angular.js:3879,13]
WARN: Dropping unused function argument cause [angular.js:4799,31]
WARN: Dropping unused function argument exception [angular.js:4799,20]
WARN: Dropping unused function argument args [angular.js:8165,28]
WARN: Dropping unused function argument args [angular.js:8231,33]
WARN: Dropping unused function argument names [angular.js:9018,32]
WARN: Dropping unused function argument name [angular.js:9030,40]
WARN: Dropping unused variable value [angular.js:9230,14]
WARN: Dropping unused function argument value [angular.js:12475,36]
[user_00@localhost ~]$ ls -lh angular.*
-rw-rw-r-- 1 user_00 user_00 479K Apr 5 01:53 angular.js
-rw-rw-r-- 1 user_00 user_00 79K May 4 16:09 angular.min.js

❷ nodejs zlib 怎麼把幾個壓縮過的文件解壓拼接

我請求管用所結束httpvar http = require("http"),
zlib = require("zlib");

function getGzipped(url, callback) {
// buffer to store the streamed decompression
var buffer = [];

http.get(url, function(res) {
// pipe the response into the gunzip to decompress
var gunzip = zlib.createGunzip();
res.pipe(gunzip);

gunzip.on('data', function(data) {
// decompression chunk ready, add it to the buffer
buffer.push(data.toString())

}).on("end", function() {
// response and decompression complete, join the buffer and return
callback(null, buffer.join(""));

}).on("error", function(e) {
callback(e);
})
}).on('error', function(e) {
callback(e)
});
}

getGzipped(url, function(err, data) {
console.log(data);
});

2. 嘗試添加encoding: null給傳遞給選項request避免載體轉換字元串並保持二進制緩沖區

3. 工作示例(使用節點請求模塊)gunzips響應function gunzipJSON(response){

var gunzip = zlib.createGunzip();
var json = "";

gunzip.on('data', function(data){
json += data.toString();
});

gunzip.on('end', function(){
parseJSON(json);
});

response.pipe(gunzip);
}

全碼:

4. 像@Iftah說設置encoding: null 完整例(少錯誤處理):request = require('request');
zlib = require('zlib');

request(url, {encoding: null}, function(err, response, body){

if(response.headers['content-encoding'] == 'gzip'){

zlib.gunzip(body, function(err, dezipped) {
callback(dezipped.toString());
}

} else {
callback(body);
}
});

❸ 如何用nodejs壓縮文件,生成tar包

你好,

我不知道如何直接使用Node.js代碼邏輯生成tar包,但我可以給你提供一個使用Node.js調用Linux命令生成tar包的方法。

首先,在npm中有一個叫做shelljs的包,在項目中安裝它:

npmi--saveshelljs

然後,在執行打包任務的js文件中使用它:

varshell=require('shelljs');
if(shell.exec('tar-zvcf文件名.tar.gz被打包的文件(夾)').code!==0){
shell.echo('Error:...');
shell.exit(1);
}

這樣就可以在當前目錄生成一個「文件名.tar.gz」的壓縮包了,而「文件名」和「被打包的文件(夾)」都可以通過參數的形式進行傳遞。

好了,更多信息可以github上搜索shelljs,希望能解決你的問題。

❹ 如何使用webpack打包ES6的Nodejs後台程序

使用webpack跟後台是否用nodejs無關,
因為webpack在執行打包壓縮的時候是依賴nodejs

❺ 如何用 webpack 打包 node

使用webpack跟後台是否用nodejs無關,因為webpack在執行打包壓縮的時候是依賴nodejs的,沒有nodejs就不能使用webpack,就好比要使用電燈,首先必須得有電流,而電流是需要發動機來發電的。

❻ 請教關於webpack壓縮nodejs代碼的問題

webpack 自帶了一個壓縮插件 UglifyJsPlugin,只需要在配置文件中引入即可。 { plugins: [ new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) ] } 加入了這個插件之後,編譯的速度會明顯變慢,所以一般只在生產環境啟

❼ 如何用nodejs實現http壓縮傳輸

推薦一個中間件,叫compression


使用見https://www.npmjs.com/package/compression

下面這個use中間件的語句寫在所有中間件的前面就行了,抓包可看到有個gzip傳輸

app.use(compression());

❽ nodejs版本的腳本壓縮和compo工具怎麼使用

一、下載並安裝NodeJS for Windows 0.6.5 或進入NodeJS官網下載最新版本。
二、查看版本:
運行cmd
node -v

npm -v

如果上訴兩個命令出錯,請打開系統環境變數Path,直接點確定。再試。
三、安裝UglifyJS 這里我們安裝最新的版本,具體版本可在npm官網查看,uglify-js版本頁面。
npm install uglify-js -g

然後等待命令完成,這個過程時間可能有點長。
如果出錯請刪除
C:\Users\Administrator\AppData\Roaming\npm 內相關內容
C:\Users\Administrator\AppData\Roaming\npm-cache 內相關內容
C:\Users\Administrator 下的錯誤信息文件
然後再次運行

四、修改配置
上述安裝後自動生成的配置文件是不可直接使用的,我們需要手工去修改。
打開C:\Users\Administrator\AppData\Roaming\npm\uglifyjs.cmd
內容為:
:: Created by npm, please don't edit manually.
"%~dp0\.\node_moles\uglify-js\bin\uglifyjs" %*

修改為:
:: Created by npm, please don't edit manually.
@IF EXIST "%~dp0"\"node.exe" (
"%~dp0"\"node.exe" "%~dp0\.\node_moles\uglify-js\bin\uglifyjs" %*
) ELSE (
node "%~dp0\.\node_moles\uglify-js\bin\uglifyjs" %*
)

五、使用uglifyjs對javascript進行壓縮美化
壓縮:
uglifyjs f.js > f.min.js

美化:
uglifyjs -b f.min.js > f.b.js

❾ 如何利用node進行js css合並壓縮

gulp是基於Node.js的前端構建工具。所以首先需要安裝nodejs,安裝nodejs。
完成nodejs安裝之後,需要使用npm安裝gulp。
先安裝全局gulp
npm install -g gulp然後在項目根目錄下安裝本地gulp。
此時項目根目錄下會多出下面這個文件夾 node_moles
好的,現在gulp已經安裝完成了,但是gulp本身不提供js壓縮合並等功能,需要使用gulp的相關插件。目前只需要完成js壓縮合並和css文件壓縮的功能,先安裝相應的插件:
1.css壓縮 gulp-minify-css
2.js壓縮 gulp-uglify
3.js合並 gulp-concat
由於壓縮之前需要對js代碼進行代碼檢測,壓縮完成之後需要加上min的後綴,我們還需要安裝另外兩個插件:

閱讀全文

與nodejs打包壓縮相關的資料

熱點內容
伺服器地址和ip地址一樣不 瀏覽:662
php中括弧定義數組 瀏覽:600
php列印堆棧 瀏覽:514
華為adb命令行刷機 瀏覽:963
人像攝影pdf 瀏覽:755
解壓文件密碼怎樣重新設置手機 瀏覽:999
高考指南pdf 瀏覽:693
爬蟲python數據存儲 瀏覽:240
u盤怎麼取消加密 瀏覽:429
567除以98的簡便演算法 瀏覽:340
pdf手機如何解壓 瀏覽:15
python描述器 瀏覽:60
戰地聯盟3解壓密碼 瀏覽:805
s型命令 瀏覽:25
php年薪5年 瀏覽:71
如何上網上設個人加密賬戶 瀏覽:44
linux打開ssh服務 瀏覽:78
微信位置可以加密嗎 瀏覽:470
演算法蠻力法 瀏覽:438
隨機排練命令 瀏覽:147