简体   繁体   English

生产使用单独的单个文件构建Angular(4)项目

[英]Production Build a Angular (4) project, with a separate individual file

So this is what is happening. 所以这就是正在发生的事情。 I have my project, and it has a configuration file. 我有我的项目,它有一个配置文件。 This configuration includes information about the app that only the client knows when they go into production mode. 此配置包括有关应用程序的信息,只有客户端在进入生产模式时才知道该应用程序。 But we don't want to give the full source code of the rest of the application, so we do have to build. 但我们不想提供应用程序其余部分的完整源代码,因此我们必须构建。 But when I execute ng build --prod this bundles and minifies all of my files. 但是当我执行ng build --prod这会捆绑并缩小我的所有文件。 I still want this, but instead of doing this for all the files in the project, it should keep the configuration file separate. 我仍然想要这个,但不是对项目中的所有文件执行此操作,而是应该将配置文件保持独立。

inline.bundle.js
polyfills.bundle.js
styles.bundle.js
vendor.bundle.js
main.bundle.js

This should become the following: 这应该成为以下内容:

inline.bundle.js
polyfills.bundle.js
styles.bundle.js
vendor.bundle.js
main.bundle.js
configuration.js

All the code is turned into JavaScript. 所有代码都变成了JavaScript。 Everything is bundled and minified, except for the configuration file. 除配置文件外,所有内容都捆绑在一起并缩小。

I can not find any documentation about this, I was hoping there would be a flag, or a setting in .angular-cli.json . 我找不到任何关于此的文档,我希望在.angular-cli.json有一个标志或设置。

It seems you need a file which has configuration and you do not want to bundle it. 您似乎需要一个具有配置的文件,并且您不希望将其捆绑。 To do so you simply can put the file in assets folder, and reference the variables from there. 为此,您只需将文件放在assets文件夹中,然后从那里引用变量即可。

.angular-cli.json .angular-cli.json

"assets": [
  "assets"
]

you may also have the file somewhere else in the project but you need to configure the same in .angular-cli.json file. 您可能还有项目中的其他位置的文件,但您需要在.angular-cli.json文件中配置相同的文件。

Read more about asset configuration here . 阅读有关资产配置的更多信息

Hope this helps!! 希望这可以帮助!!

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

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