简体   繁体   English

使用 browserify 捆绑 js 文件

[英]bundling js files with browserify

I am working with Angularjs as my front end.我正在使用 Angularjs 作为我的前端。 i was using grunt as build tool but now i want to switch to npm as my build tool as per below link.我使用 grunt 作为构建工具,但现在我想按照以下链接切换到 npm 作为我的构建工具。

npm script as build tool npm 脚本作为构建工具

now the actual problem is while bundling JS without Grunt现在实际的问题是在没有 Grunt 的情况下捆绑 JS

in Grunt we can have concate task which is quite easy to configure.在 Grunt 中,我们可以有 concate 任务,这很容易配置。 mention below js: ["src/*.js", "src/**/*.js", "!src/apiG/*.js", "!src/apiG/**/*.js"] ,下面提到js: ["src/*.js", "src/**/*.js", "!src/apiG/*.js", "!src/apiG/**/*.js"] ,

right now as per my limited knowledge Browserify can be use for bundling all my local javascript.(if anyone can suggest me any other package for bundling my javascript files .. Welcome !!)现在,根据我有限的知识, Browserify可用于捆绑我所有的本地 javascript。(如果有人可以向我推荐任何其他用于捆绑我的 javascript 文件的包.. 欢迎使用!!)

With browserify i have tried following in my package.json but it didnt work使用 browserify 我尝试在我的 package.json 中遵循但它没有用

 "build:bundle": "browserify "src/*.js", "src/**/*.js", "!src/apiG/*.js", "!src/apiG/**/*.js" -o ./dist/js/bundle.js",

can anyone suggest me how to bundle nested javascript with all options like ignore and all.任何人都可以建议我如何将嵌套的 javascript 与所有选项(如忽略和全部)捆绑在一起。 in browserfy.在浏览器中。

i dnt wanted to use "require()" to include all javascript.我不想使用“require()”来包含所有的javascript。 just want simple bundling of all the files in my project and ignore vendor files.只想简单地捆绑我的项目中的所有文件并忽略供应商文件。 etc..等等..

also if someone can suggest for minification as well.如果有人也可以建议缩小。 :) (i am expecting too much here i know :) ) :)(我在这里期待太多,我知道:))

Thanks in Advance.提前致谢。

Use bash to find all files, prune the unwanted ones and concatenate the contents:使用 bash 查找所有文件,修剪不需要的文件并连接内容:

find src -type f -name \*.js | egrep -v 'src/apiG/' | xargs cat >dist/js/bundle.js

If you require additional processing, simply pipe it through the appropriate command(s) at the end before writing to bundle.js如果您需要额外的处理,只需在写入 bundle.js 之前通过适当的命令在末尾进行管道传输

find src -type f -name \*.js | egrep -v 'src/apiG/' | xargs cat | minify_command >dist/js/bundle.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM