gpt4 book ai didi

angular - 在我的案例中,如何捆绑用于生产的 Angular 2 应用程序?

转载 作者:搜寻专家 更新时间:2023-10-30 21:20:04 24 4
gpt4 key购买 nike

我读了这篇文章 - http://blog.mgechev.com/2016/06/26/tree-shaking-angular2-production-build-rollup-javascript/我想将第一步 Simple build with minification. 包含到我的应用程序中。到目前为止,我是这样配置的:

system.config.js

(function (global) {
System.config({
paths: {
'npm:': 'node_modules/'
},
map: {
app: 'js',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'@ng-bootstrap/ng-bootstrap': 'node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js'
},
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
primeng: {
defaultExtension: 'js'
}
}
});
})(this);

index.html

<script src="systemjs.config.js"></script>    
<script src="app.config.js"></script>
<script>
System.import('app').then(
function(module) {
return module.start(appConfig, messagePropsData);
}).catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>

tsconfig.json

{
"compilerOptions": {
"target": "ES5",
"module": "CommonJS",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"inlineSourceMap": false,
"inlineSources": false,
"outDir": "js"
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
],
"compileOnSave": true
}

ma​​in.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { ValueProvider } from '@angular/core';
import { AppModule } from './app.module';
import { AppConfig, APP_CONFIG, CONFIG_PROVIDER } from './app.config';
export function start(config: any) {
CONFIG_PROVIDER.provider = { provide:APP_CONFIG, useValue: config }
return platformBrowserDynamic([CONFIG_PROVIDER.provider]).bootstrapModule(AppModule);
}

正如您在使用此命令时看到的那样 "start": "tsc && concurrently\"tsc -w\"\"lite-server\"" 我生成的所有 .ts 文件中的 js 文件在 js 目录中创建。现在我可以使用文章中的 build_prod 命令(当然将其更改为 js 目录)在该目录中制作 bundle 和缩小包。问题是我已经告诉我的应用程序在该目录中查找 main.js 文件,我不想将捆绑文件 main.js 命名为好吧(app.bundle.minified.js 更好)(该命令将首先从 js 目录中删除所有其他文件并仅放置捆绑文件),那么我如何告诉我的应用程序开始它应该寻找 app.bundle.minified.js 文件开始,然后是 app.bundle.js 文件,然后是 main .js

基本上我不希望应用程序以捆绑的缩小版本开始,如果找不到该版本,它应该从 main.js 文件开始。我应该在 system.config.jsindex.html 中更改什么。我该怎么做?

最佳答案

我认为,您可以使用 angular-cli 来生成和构建 angular2 项目

Angular-Cli

ng-build 可用于为不同环境构建项目。

Build Targets and Environment Files

关于angular - 在我的案例中,如何捆绑用于生产的 Angular 2 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com