Angular 2/4 : what is the difference between the scripts. bundle.js 和 vendor.bundle.js?

标签 angular angular-cli

Angular 4:运行命令后:ng build 我有这个结构

0.chunk.js      favicon.ico           polyfills.bundle.js.map
0.chunk.js.map  index.html            scripts.bundle.js
1.chunk.js      inline.bundle.js      scripts.bundle.js.map
1.chunk.js.map  inline.bundle.js.map  styles.bundle.js
2.chunk.js      main.bundle.js        styles.bundle.js.map
2.chunk.js.map  main.bundle.js.map    vendor.bundle.js
assets          polyfills.bundle.js   vendor.bundle.js.map

What is the difference between the scripts.bundle.js and the vendor.bundle.js?

我认为不同之处在于,scripts.bundle.js 包含所有外部 .js 文件,而 vendor.bundle.js 包含所有创建的模块。

编辑

but I can import .js files from node_modules into the vendor.bundle.js and the scripts.bundle.js. What the best approach is: importing .js files into modules or adding them into the .angular-cli.jsons scripts object?

~非常感谢您的帮助!

最佳答案

scripts.bundle.js 表示您在 .angular-cli.json
中配置的 scripts 部分 vendor.bundle.js 包含您在 app.module 中引用的 npm 模块

The better way to figure out what is inside your bundles is to use webpack-bundle-analyzer

添加 "analyze": "ng build --prod --stats-json && webpack-bundle-analyzer dist/stats.json", 到你的 package.json 一旦你 npm install webpack-bundle-analyzer 运行 npm run analyze

.angular-cli.jsonscripts 部分的目的是处理遗留脚本,但您也可以使用它来改进您的延迟加载故事。只说你的 block 依赖于一些特定的 npm 模块。在这种情况下,不需要将该 npm 模块放入 vendor.bundle.js,因为它可以在加载相关 block 之前加载。

有关 https://github.com/angular/angular-cli/wiki/stories-global-scripts 上脚本部分的更多详细信息

关于Angular 2/4 : what is the difference between the scripts. bundle.js 和 vendor.bundle.js?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46398801/

相关文章:

angular - NgRx 效果 mergeMap 方法

angular - Ng-select 在对话框中添加额外的隐藏高度

Angular Material 表单元格 :after element

javascript - 读取组件文件 Angular 中的响应 header

javascript - Angular 2根据用户输入重新加载当前组件

angularjs - Angular2 教程(英雄之旅): Cannot find module './app-routing.module'

Angular 从版本 5 降级到版本 4

angular - 在 Angular 应用程序之间共享代码

angular - 我无法构建和运行 Angular 应用程序: 'An unhandled exception occurred: NGCC failed.' has anyone got suggestions on how to resolve this?

angular-cli - 如何使用 Angular-Cli 在不在/src/app 的文件夹中创建组件