4
當我嘗試使用--prod選項運行ng build時,它會編譯爲一個主文件。 js文件,並且在控制檯中沒有出現錯誤。如何在Angular 2 CLI中使用「ng build --prod」和「ng serve --prod」,得到404錯誤
但是,當我在瀏覽器中運行應用程序它仍然尋找個人js文件。
我main.ts:
// default
import { provide, enableProdMode, ExceptionHandler } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS, Http } from '@angular/http';
// External
import {
TranslateService, TranslateLoader, TranslateStaticLoader
} from 'ng2-translate/ng2-translate';
import {Angulartics2} from 'angulartics2';
// mine
import { CustomExceptionHandler } from './app/_common/CustomExceptionHandler';
import { UserService } from './app/_services/user.service';
import { MessagesService } from './app/_services/messages.service';
import { APP_ROUTER_PROVIDERS } from './app/app.routes';
import { App, environment } from './app/';
if (environment.production) {
enableProdMode();
}
bootstrap(App, [
APP_ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(ExceptionHandler, { useClass: CustomExceptionHandler }),
provide(LocationStrategy, { useClass: HashLocationStrategy }),
{
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
deps: [Http]
},
Angulartics2,
TranslateService,
MessagesService,
UserService
])
.then(() => {
console.log('Angular 2 loaded');
})
.catch(err => console.error(err));
當應用程序在它看起來
app/_services/messages.service.js
app/_services/user.service.js
app/app.routes.js
etc...
瀏覽器中運行所有這些請求的過程中獲得的404,因爲JS文件都被壓縮到一個main.js文件。我如何避免這種情況?
你可以檢查正確main.js正擔任? –
@ArpitAgarwal我相信這是 – ganjan