PhpStorm将多个JavaScript文件缩小为1 [英] PhpStorm minify multiple JavaScript files in 1

查看:128
本文介绍了PhpStorm将多个JavaScript文件缩小为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PhpStorm的文件观察器来缩小我的JavaScript文件,但我无法按照我希望的方式使用它。

I wanted to minify my JavaScript files using PhpStorm's file watcher but I can't get it working the way I would like it to.

我已经安装了uglify- JS。在文件观察器中,我尝试了以下内容:

I have installed uglify-js. In the file watcher I tried the following:


参数: $ FileName $ -o $ FileDir $ .min。 js - style compressed

刷新输出路径: $ FileDir $ .min.js

问题是每次只有1个文件被缩小。

The problem is that there is just 1 file being minified each time not all in one.

另一个问题是我想输出一个源图,但我不知道该怎么做,也不知道放在哪里(参数或输出路径)。

The other problem is that I would like to output a sourcemap but I don't know how to do this nor where to put it (arguments or output paths).

I希望有人可以帮助我完成这些设置。

I hope someone could help me with these settings.

推荐答案

关于文件监视器的几点说明:

Few notes on File Watchers:


  • 文件观察器主要用于在保存时对文件执行一些外部操作。

  • 为每个修改过的文件调用文件观察器。

  • 如果要一次处理多个文件(例如:合并2个以上的文件到1)使用File Watcher然后你需要对所有参与文件进行硬编码(而不是使用当前文件宏 $ FileName $ ),当然,除非uglify支持文件掩码(例如 / path / to / folder / * .js )。

  • 如果从目标列表中修改2个文件,则文件将为每个人调用Watcher,因此即使使用硬编码文件名,也会执行两次(相同的工作完成两次)。

  • File watchers were designed primarily to perform some external actions on file on save.
  • File watcher gets called for each modified file.
  • If you want to process multiple files in one go (for example: merge 2+ files into 1) using File Watcher then you need to hard code all participating files (as opposed to using current file macro $FileName$ for that), unless, of course, uglify supports file masks (e.g. /path/to/folder/*.js).
  • If you modify 2 files from the target list then File Watcher will be called for each of them so even with hard coded file names it will be performed twice (same job done twice).

考虑到上述我建议使用Grunt或Gulp任务 - 它们更适合此类要求。

Considering the above I suggest using Grunt or Gulp task for that instead -- they're more suitable for such requirements.

PS
如果您希望在File Watcher中实际使用这样的grunt / gulp任务(与在终端/控制台中手动调用它一样),但由于上面的第3点,更好的解决方案是使用Grun如果您需要自动执行任务,请查看/ Gulp的监视模块/功能。

这篇关于PhpStorm将多个JavaScript文件缩小为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆