自定义捆绑包文件名angular-cli [英] custom bundle file name angular-cli

查看:90
本文介绍了自定义捆绑包文件名angular-cli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular-cli:1.0.0-beta.28.3捆绑项目文件.当我运行ng build时,它将在dist文件夹下创建main.bundle.js文件.

I'm using angular-cli: 1.0.0-beta.28.3 to bundle the project files. When i run ng build, it creats main.bundle.js file under dist folder.

我想提供一个自定义名称(例如:myproject.js),而不是main.bundle.js.使用ng build时,有没有办法提供自定义输出文件名.

Instead of main.bundle.js I want to give a custom name (example: myproject.js). Is there a way to provide a custom output file name when using ng build.

推荐答案

不幸的是,捆绑包名称不可配置.在构建Wiki中没有针对这种情况的选项: https://github.com/angular/angular-cli/wiki/build

Unfortunately no, the bundle names cannot be configurable. There is no option for such thing in the build wiki: https://github.com/angular/angular-cli/wiki/build

但是,您可以运行一个简单的nodejs脚本来为您完成此操作:

however, you can run a simple nodejs script to do that for you:

// rename.js file - location, right next to package.json
var fs = require("fs");
fs.rename("./dist/main.bundle.js", "./dist/myproject.js");

然后在package.json中添加一个新的script,将其命名为build-rename

then in your package.json, add a new script call it something like build-rename

"scripts":{
   "build-rename":"ng build && node rename.js"
}

现在运行脚本npm run build-rename

这篇关于自定义捆绑包文件名angular-cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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