0
我試圖用uglifyjs將javascript文件縮小爲一個文件,但它不起作用。我使用$ node uglifyjs.js來運行該文件。下面是uglify.js代碼如何使用uglifyjs將多個文件縮減爲一個文件?
var fs = require('fs');
var uglifyjs = require('uglify-js');
var files = ['app.js', 'geolocation.service.js'];
var result = uglifyjs.minify(fs.readFileSync(files, 'utf8'));
console.log(result.code);
fs.writeFile("output.min.js", result.code, function(err){
if(err){
console.log(err);
} else {
console.log("File was successfully saved.");
}
});
當我運行這段代碼,我得到了以下錯誤消息:
fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags),
mode);
^
TypeError: path must be a string
at TypeError (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.readFileSync (fs.js:397:15)
at Object.<anonymous> (C:\Users\HP\Desktop\uglify\uglify.js:7:33)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:134:18)
'fs.readFileSync(文件[,選項])' - '文件 | | 文件名或文件描述符' –
elclanrs