简体   繁体   English

如何从 Angular 应用程序中查看 webpack 配置?

[英]How to see webpack config from angular application?

I create angular application using ng new my-app command.我使用ng new my-app命令创建 Angular 应用程序。

How I can see webpack.config that Angular built for my app?如何查看 Angular 为我的应用构建的webpack.config I don't want to customize this webpack config.我不想自定义这个 webpack 配置。 just to log it to file/screen...只是将其记录到文件/屏幕...

Angular core webpack config is placed in node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js and you can change the parameters there. Angular核心webpack 配置位于node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js中,您可以在那里更改参数。

Suggestion is to create a patch.js file to change the file after every npm update to prevent rewriting codes.建议是创建一个patch.js文件,以便在每次npm update后更改该文件,以防止重写代码。

And if you are talking about the webpack to use in building your additional package you have to create config file yourself and reference that in angular.json如果您正在谈论用于构建附加包的webpack ,您必须自己创建配置文件并在angular.json中引用它

I wanted to have a custom webpack config file like you and implement it as below:我想有一个像你一样的自定义 webpack配置文件并按如下方式实现它:

  1. Install custom-webpack library安装自定义 webpack 库

    npm i -D @angular-builders/custom-webpack
  2. Add the following configurations to angular.json file将以下配置添加到 angular.json 文件中

    "architect": { ... "build": { "builder": "@angular-builders/custom-webpack:browser", "options": { "customWebpackConfig": { "path": "./webpack.config.js" }, ... } }
  3. If your project configured with angular universal (SSR) then you should add following configurations in your angular.json file too:如果您的项目配置了 Angular Universal (SSR),那么您也应该在 angular.json 文件中添加以下配置:

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

    } }

  4. Create webpack.config.js in the root of your application project and write your custom webpack configurations in it在应用程序项目的根目录中创建webpack.config.js并在其中编写自定义 webpack 配置

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

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