1 Star 2 Fork 4

桐溪漂流 / admin-angular

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
4.webpack-config.md 1.32 KB
一键复制 编辑 原始数据 按行查看 历史

angular中自定义webpack配置

用到 @angular-builders/custom-webpack 依赖

安装 custom-webpack

  • angular - 12.2.0
  • @angular-builders/custom-webpack - 12.1.1

以下方式选一,本文创建的时候,依赖都是最新版本的,如果需要特定版本,则需要添加特定版本号

  • npm i -D @angular-builders/custom-webpack
  • yarn add @angular-builders/custom-webpack --dev

调整angular.json

{
  // ...省略配置
  "projects": {
    "project-name": {
      // ...省略配置
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            // ...省略配置
            "customWebpackConfig": {
              "path": "./webpack.config.js"
            }
          },
          // ...省略配置
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          // ...省略配置
        },
        // ...省略配置
      }
    }
  },
  // ...省略配置
}

webpack.config.js

module.exports = config => {
  config.devServer = Object.assign(config.devServer, {
    port: 9000,
    before: (app, server, compiler) => {
      app.get('/list', (req, res)=>{
        res.json({ success: true, code: 200, data: [] });
      })
    },
  })
  return config;
}
1
https://gitee.com/baoyinYang/admin-angular.git
git@gitee.com:baoyinYang/admin-angular.git
baoyinYang
admin-angular
admin-angular
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891