首页 文章

如何通过Angular CLI为生成的块设置mime类型?

提问于
浏览
2

在我的Angular应用程序中,我使用延迟加载来为特定路径上的模块提供服务 . 当我构建我的应用程序时,它会在dist文件夹中生成块 .

当我试图在浏览器中加载我的应用程序时,它会抛出错误:“拒绝从'0.chunk.js'执行脚本,因为它的MIME类型('text / html')不可执行,并且严格的MIME类型检查已启用 . “

无论如何我可以在生成文件时添加MIME类型或禁用MIME类型检查?

我有一个基本的路由文件包含:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const appRoutes: Routes = [
    {
        path: '',
        redirectTo: 'app',
        pathMatch: 'full'
    },
    {
        path: ‘new’,
        loadChildren: 'app/base/new/new.module#NewModule'
    }
 ];

@NgModule({
  imports: [
    RouterModule.forRoot(appRoutes),
  ],
})
export class AppRoutingModule {
}

我使用package.json中的以下命令构建我的应用程序:

"build": "rm -rf dist && ng build --prod --output-hashing none --build-optimizer",

在dist文件夹中,它会生成:

chunk {0} 0.chunk.js () 2.54 kB  [rendered]
chunk {1} 1.chunk.js () 262 kB  [rendered]
chunk {2} main.bundle.js (main) 942 kB [initial] [rendered]
chunk {3} polyfills.bundle.js (polyfills) 94.9 kB [initial] [rendered]
chunk {4} styles.bundle.css (styles) 50.5 kB [initial] [rendered]
chunk {5} inline.bundle.js (inline) 1.36 kB [entry] [rendered]

1 回答

相关问题