简体   繁体   English

angular-cli在哪里是webpack.config.js文件 - 新的angular6不支持ng弹出

[英]angular-cli where is webpack.config.js file - new angular6 does not support ng eject

UPDATE: December 2018 (see 'Aniket' answer) 更新:2018年12月(参见'Aniket'回答)

With Angular CLI 6 you need to use builders as ng eject is deprecated and will soon be removed in 8.0 使用Angular CLI 6,您需要使用构建器,因为不推荐使用ng eject,并且很快将在8.0中删除

UPDATE: June 2018: Angular 6 does not support ng eject** 更新:2018年6月:Angular 6不支持ng弹出**

UPDATE: February 2017: use ng eject 更新:2017年2月:使用ng弹出

UPDATE: November 2016: angular-cli now only use webpack. 更新:2016年11月:angular-cli现在只使用webpack。 You only need install normally with npm install -g angular-cli. 您只需要使用npm install -g angular-cli正常安装。 "We changed the build system between beta.10 and beta.14, from SystemJS to Webpack.", but actually i use angular-cli just to firs structure and folders and then anymore, i use webpack config manually “我们改变了beta.10和beta.14之间的构建系统,从SystemJS到Webpack。”但实际上我只使用angular-cli来结构和文件夹,然后再使用webpack配置

I've installed angular cli with this: 我安装了角度cli:

npm install -g angular-cli@webpack

When I worked with angular1 and web pack , i used to modify "webpack.config.js" file to execute all the task and plugins, but i don't see on this project created with angular-cli who does it work. 当我使用angular1和web pack时,我曾经修改过“webpack.config.js”文件来执行所有的任务和插件,但我没有看到使用angular-cli创建的这个项目是谁工作的。 it's magic? 这是魔法?

I see Webpack is working when i do: 当我这样做时,我看到Webpack正在工作:

ng serve 

"Version: webpack 2.1.0-beta.18"

but i don't understand the way that angular-cli config works... 但我不明白angular-cli配置的工作方式......

There's a nice way to eject webpack.config.js from angular-cli . 有一种从angular-cli中弹出webpack.config.js的好方法。 Just run: 赶紧跑:

$ ng eject

This will generate webpack.config.js in the root folder of your project, and you're free to configure it the way you want. 这将在项目的根文件夹中生成webpack.config.js,您可以根据需要自由配置它。 The downside of this is that build/start scripts in your package.json will be replaced with the new commands and instead of 这样做的缺点是package.json中的build / start脚本将被替换为新命令而不是

$ ng serve

you would have to do something like 你必须要做类似的事情

$ npm run build & npm run start

This method should work in all the recent versions of angular-cli (I personally tried a few, with the oldest being 1.0.0-beta.21 , and the latest 1.0.0-beta.32.3 ) 这个方法应该适用于所有最新版本的angular-cli(我个人试过几个,最老的是1.0.0-beta.21 ,最新的1.0.0-beta.32.3

According to this issue , it was a design decision to not allow users to modify the Webpack configuration to reduce the learning curve. 根据这个问题 ,设计决定是不允许用户修改Webpack配置以减少学习曲线。

Considering the number of useful configuration on Webpack, this is a great drawback. 考虑到Webpack上有用的配置数量,这是一个很大的缺点。

I would not recommend using angular-cli for production applications, as it is highly opinionated. 我不建议将angular-cli用于生产应用程序,因为它是高度自以为是。

With Angular CLI 6 you need to use builders as ng eject is deprecated and will soon be removed in 8.0. 使用Angular CLI 6,您需要使用构建器,因为不推荐使用ng eject,并且很快将在8.0中删除。 That's what it says when I try to do an ng eject 当我尝试进行弹出时,它就是这么说的

在此输入图像描述

You can use angular-builders package ( https://github.com/meltedspark/angular-builders ) to provide your custom webpack config. 您可以使用angular-builders包( https://github.com/meltedspark/angular-builders )来提供自定义webpack配置。

I have tried to summarize all in a single blog post on my blog - How to customize build configuration with custom webpack config in Angular CLI 6 我试图在我的博客上的一篇博客文章中总结所有内容 - 如何使用Angular CLI 6中的自定义webpack配置自定义构建配置

but essentially you add following dependencies - 但基本上你添加以下依赖项 -

  "devDependencies": {
    "@angular-builders/custom-webpack": "^7.0.0",
    "@angular-builders/dev-server": "^7.0.0",
    "@angular-devkit/build-angular": "~0.11.0",

In angular.json make following changes - angular.json中进行以下更改 -

  "architect": {
    "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "customWebpackConfig": {"path": "./custom-webpack.config.js"},

Notice change in builder and new option customWebpackConfig. 请注意构建器和新选项customWebpackConfig中的更改。 Also change 也改变

    "serve": {
      "builder": "@angular-builders/dev-server:generic",

Notice the change in builder again for serve target. 请注意对于服务目标的构建器的更改。 Post these changes you can create a file called custom-webpack.config.js in your same root directory and add your webpack config there. 发布这些更改后,您可以在同一根目录中创建名为custom-webpack.config.js的文件,并在其中添加您的webpack配置。

However, unlike ng eject configuration provided here will be merged with default config so just add stuff you want to edit/add. 但是,与此处提供的ng弹出配置不同,它将与默认配置合并,因此只需添加要编辑/添加的内容。

The CLI's webpack config can now be ejected. 现在可以弹出CLI的webpack配置。 Check Anton Nikiforov's answer . 检查Anton Nikiforov的回答


outdated: 过时的:

You can hack the config template in angular-cli/addon/ng2/models . 您可以在angular-cli/addon/ng2/models破解配置模板。 There's no official way to modify the webpack config as of now. 截至目前,还没有正式的方法来修改webpack配置。

There's a closed "wont-fix" issue on github about this: https://github.com/angular/angular-cli/issues/1656 关于这个问题,github上有一个封闭的“不会修复”问题: https//github.com/angular/angular-cli/issues/1656

What I am thinking is having webpack would be easy when production release. 我想的是在生产发布时让webpack很容易。

FYI : https://github.com/Piusha/ngx-lazyloading 仅供参考: https//github.com/Piusha/ngx-lazyloading

As per the suggestion of ng eject you can use ngx-build-plus 根据ng eject的建议,您可以使用ngx-build-plus

There are several projects that can be used in conjuction with the new configuration format that provide the benefits of ejecting without the maintenance overhead. 有几个项目可以与新的配置格式结合使用,提供弹出的好处,而无需维护开销。 One such project is ngx-build-plus found here: https://github.com/manfredsteyer/ngx-build-plus 其中一个项目是ngx-build-plus,请点击此处: https//github.com/manfredsteyer/ngx-build-plus

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

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