UglifyJS

编程入门 行业动态 更新时间:2024-10-24 06:31:55
UglifyJS - 如何输出到不同的文件夹?(UglifyJS - how to output to a different folder?)

我正在尝试使用UglifyJS来缩小我的代码,但我遇到了一些问题。 我有一个像这样的文件结构:

/deploy /assets /js ((minified file goes here)) /js script-compiled.js

我想在位于我的私人文件夹中的js/script-compiled.js上运行UglifyJS,并让它在我的deploy/js (上传到我网站的js)文件夹中输出一个script.min.js文件。 这是我到目前为止的命令:

uglifyjs js/script-compiled.js --compress --mangle --screw-ie8 -o > deploy/assets/js/script.min.js

这给了我这个错误:

fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ TypeError: path must be a string

我有点困惑。 是否可以将文件输出到其他目录? 也许这只是一个普通的Bash事情。 谢谢!

I'm trying to use UglifyJS in order to minify my code but I'm running into a bit of a problem. I have a file structure like so:

/deploy /assets /js ((minified file goes here)) /js script-compiled.js

I want to run UglifyJS on js/script-compiled.js located in my private folder and have it output a script.min.js file in my deploy/js (the js that gets uploaded to my website) folder. Here's what I have so far for my command:

uglifyjs js/script-compiled.js --compress --mangle --screw-ie8 -o > deploy/assets/js/script.min.js

Which gives me this error:

fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ TypeError: path must be a string

I'm a little confused. Is it possible to output a file to a different directory? Maybe this is just a general Bash thing. Thanks!

最满意答案

您指定了-o选项但未提供值。 来自文档 :

-o filename或--output filename - 将结果放在filename中。 如果没有给出,结果将转到标准输出(或参见下一个)。

所以要么这样做

uglifyjs ... -o deploy/assets/js/script.min.js

或省略-o并重定向标准输出

uglifyjs ... > deploy/assets/js/script.min.js

You specified the -o option but you didn't provide a value. From the docs:

-o filename or --output filename — put the result in filename. If this isn’t given, the result goes to standard output (or see next one).

So either do

uglifyjs ... -o deploy/assets/js/script.min.js

or omit -o and redirect stdout

uglifyjs ... > deploy/assets/js/script.min.js

更多推荐

本文发布于:2023-08-04 08:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UglifyJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!