简体   繁体   English

如何使用 webpack 忽略模块?

[英]How to use webpack to ignore a module?

I have shared code that is used in the backend and frontend (I use Next for the frontend).我共享了用于后端和前端的代码(我使用 Next 作为前端)。

A piece of the shared code (library):一段共享代码(库):

import { ApiProperty } from '@nestjs/swagger'

export class AccessTokenResponseDto {
    @ApiProperty({
        example: 'xxxxx.xxxxx.xxxxx',
    })
    public token!: string
}

Now I want to ignore @nestjs/swagger in the frontend BUT do not lose the functionality of the documentation feature in the backend.现在我想在前端忽略@nestjs/swagger但不要失去后端文档功能的功能。

The reason why I want to ignore nestjs in the frontend is to reduce the build size.我想在前端忽略nestjs的原因是为了减少构建大小。

Try this: https://webpack.js.org/configuration/externals/#root试试这个: https://webpack.js.org/configuration/externals/#root

The externals configuration can exclude dependencies. externals 配置可以排除依赖项。

And you need two different script in package.json to distinguish different building env(one for frontend, one for backend).您需要在 package.json 中使用两个不同的脚本来区分不同的构建环境(一个用于前端,一个用于后端)。

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

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