忽略ng build --prod中的`assets`文件夹 [英] ignore `assets` folder from ng build --prod

查看:166
本文介绍了忽略ng build --prod中的`assets`文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在其中包含assets文件夹

I want not to include assets folder in

ng build --prod

ng build --prod

但是我运行时assets文件夹应该可用

But assets folder shall be available when i am running

ng serve

我尝试过如下编写:

apps:[
   exclude: ["assets"]
]

但是这没有用. 也尝试了以下解决方案

But this did not work. Tried the solution as below as well

https://github.com/angular/angular-cli/issues/5435

但是没有一个起作用.任何帮助将不胜感激.

But none of it is working. Any help will be appreciated.

推荐答案

我有一个非常相似的场景,因为在使用aot进行构建时,我不想复制资产文件夹. 找到这篇文章 ,我最终在.angular-cli.json中复制了我的应用程序配置,每个应用程序配置都有其唯一的名称(在我的情况下为 devApp aotApp ),如下所示:

I had a very similar scenario, since I didn't want to copy the assets folder when building using aot. After finding this article, I ended up duplicating my app config at the .angular-cli.json, each one with its unique name (in my case devApp and aotApp) like this:

"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
    "name": "my-project"
},
"apps": [
    {
        "name": "devApp",
        "root": "src",
        "outDir": "wwwroot",
        "assets": [
            "assets",
            "favicon.ico"
        ],
        "index": "index.html",
        "main": "main.ts",
        "polyfills": "polyfills.ts",
        "test": "test.ts",
        "tsconfig": "tsconfig.app.json",
        "testTsconfig": "tsconfig.spec.json",
        "prefix": "app",
        "styles": [
            "styles.scss"
        ],
        "scripts": [
        ],
        "environmentSource": "environments/environment.ts",
        "environments": {
            "dev": "environments/environment.ts",
            "prod": "environments/environment.prod.ts"
        }
    }
    ,
    {
        "name": "aotApp",
        "root": "src",
        "outDir": "wwwroot",
        "assets": [
        ],
        "index": "index.html",
        "main": "main.ts",
        "polyfills": "polyfills.ts",
        "test": "test.ts",
        "tsconfig": "tsconfig.app.json",
        "testTsconfig": "tsconfig.spec.json",
        "prefix": "app",
        "styles": [
            "styles.scss"
        ],
        "scripts": [
        ],
        "environmentSource": "environments/environment.ts",
        "environments": {
            "dev": "environments/environment.ts",
            "prod": "environments/environment.prod.ts"
        }
    }
],
--- and then the rest of the configuration

所以...要开发,我使用ng serve --app devApp(尽管似乎ng serve也可以使用),当我需要生成用于生产的捆绑包时,我运行ng build --app aotApp --prod.

So... to develop I use ng serve --app devApp (although It seems that just ng serve also works), and when I need to generate the bundles for production, I run ng build --app aotApp --prod.

这篇关于忽略ng build --prod中的`assets`文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆