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

查看:38
本文介绍了自定义包文件名 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.

我想给一个自定义名称而不是 main.bundle.js(例如:myproject.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/角度/角度-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天全站免登陆