我正在按照本教程使用汇总构建生产版本:http: //blog.mgechev.com/2016/06/26/tree-shaking-angular2-production-build-rollup-javascript/
生产部分运行良好,但是当我想使用npm run start
(清理 js 目录、编译 .ts 文件并监视更改的脚本)进行开发时,构建失败并出现404
异常,表示它 failed to find
traceur
。唯一值得注意的区别是文件中的fromes5
和commonjs
to更改。如何解决此问题以使精简版服务器正常工作。es2015
tsconfig
错误
GET http://localhost:3000/traceur 404 (Not Found)
scheduleTask @ zone.js:1561
ZoneDelegate.scheduleTask @ zone.js:242
Zone.scheduleMacroTask @ zone.js:168
(anonymous) @ zone.js:1584
send @ VM1385:3
fetchTextFromURL @ system.src.js:1051
(anonymous) @ system.src.js:1781
ZoneAwarePromise @ zone.js:525
(anonymous) @ system.src.js:1780
(anonymous) @ system.src.js:2809
(anonymous) @ system.src.js:3387
(anonymous) @ system.src.js:3701
(anonymous) @ system.src.js:4093
(anonymous) @ system.src.js:4556
(anonymous) @ system.src.js:4825
(anonymous) @ system.src.js:407
ZoneDelegate.invoke @ zone.js:229
Zone.run @ zone.js:113
(anonymous) @ zone.js:509
ZoneDelegate.invokeTask @ zone.js:262
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:405
ZoneTask.invoke @ zone.js:336
(index):44 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur
Error: XHR error (404 Not Found) loading http://localhost:3000/traceur
at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:851:29) [<root>]
at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:332:33) [<root>]
Error loading http://localhost:3000/traceur
Unable to load transpiler to transpile http://localhost:3000/js/main.js
Error loading http://localhost:3000/js/main.js
at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3000/node_modules/zone.js/dist/zone.js:851:29) [<root>]
at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:151:47) [<root> => <root>]
at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:332:33) [<root>]
Error loading http://localhost:3000/traceur
Unable to load transpiler to transpile http://localhost:3000/js/main.js
Error loading http://localhost:3000/js/main.js
旧版
{
"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
}
新版本
{
"compilerOptions":{
"target":"es2015",
"module":"es2015",
"moduleResolution":"node",
"lib":[
"es6",
"es2015",
"dom"
],
"sourceMap":true,
"emitDecoratorMetadata":true,
"experimentalDecorators":true,
"removeComments":false,
"noImplicitAny":false,
"inlineSourceMap":false,
"inlineSources":false,
"outDir":"js",
"typeRoots":[
"./node_modules/@types",
"./node_modules"
],
"types":[
]
},
"exclude":[
"node_modules",
"typings/main",
"typings/main.d.ts"
],
"compileOnSave":true
}
system.config.js
/** * System configuration for Angular samples * Adjust as necessary for your application needs. */
(function(global) {
System.config({
paths: {
'npm:': 'node_modules/'
},
map: {
app: 'js',
'@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',
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'primeng': 'npm:primeng',
'@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);