简体   繁体   English

angular-cli @ webpack如何工作?

[英]How does angular-cli@webpack work?

I have used angular-cli with systemJS and am now comfortable with its build process,test cases & component interaction. 我在systemJS中使用了angular-cli,现在对它的构建过程,测试用例和组件交互感到满意。

recently I upgraded my angular-cli to angular-cli@webpack . 最近,我将我的angular-cli升级到angular-cli@webpack

But I am pretty confused with following things: 但是我对以下事情感到很困惑:

  1. How does webpack build process works? Webpack构建过程如何工作?
  2. How can I install third party libraries like lodash,ng2-bootstrap etc with this webpack configuration as I cant see any webpack.config.ts file. 如何使用此webpack配置安装lodash,ng2-bootstrap等第三方库lodash,ng2-bootstrap因为我看不到任何webpack.config.ts文件。
  3. Why does it not show any bundle which contains JS files of my application? 为什么不显示任何包含我的应用程序JS文件的包?
  4. I can only see typescript files of my application..why? 我只能看到应用程序的打字稿文件。为什么?

Thanks in advance. 提前致谢。

  1. When u run ng build it will build everything and output the files to the Dist folder 当您运行ng build ,它将构建所有内容并将文件输出到Dist文件夹
  2. Just run npm install 'external-dependency' and you're good to go, just import it in the files u need it (and in app.module.ts) 只需运行npm install 'external-dependency' ,就可以了,只需将其导入您需要的文件(以及app.module.ts中)
  3. U need to run ng build first, see 1 您需要先运行ng build ,请参见1
  4. See 1 查看1
  1. webpack read entry and build to desired output. webpack读取条目并生成所需的输出。 here is an example 这是一个例子

      entry: { 'app': './main.ts'//your entry point }, output: { path: helpers.root('dist'), filename: 'bundle.js' //your build file } 
  2. It's simple, install your dependencies through npm and require them in your project and webpack will take care of them means it will bundle them into your build. 很简单,通过npm安装依赖项,并在项目中要求它们,而webpack会照顾它们,这意味着将它们捆绑到您的构建中。

    Example

    npm install lodash

and in your project 在你的项目中

require("lodash")
  1. when you run application with ng-serve it does not build physicals files, it serve from memory and tha't why you don't see any file. 当您使用ng-serve运行应用程序时,它不会生成物理文件,而是从内存中提供文件,这就是为什么您看不到任何文件的原因。
  2. As long you are running your application with ng-serve it will not show you physicals files but if you run ng-build it will build physicals files to dist folder and you will be able to see them. 只要您使用ng-serve运行您的应用程序,它就不会显示物理文件,但是如果您运行ng-build,它将把物理文件构建到dist文件夹,您将能够看到它们。

read more about webpack it's awesome 阅读有关webpack的更多信息,它很棒

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

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