프리 렌더 노드와 개인 프리 렌더링 서버를 사용하여 Angular2/Express 응용 프로그램을 미리 렌더링하려고합니다. 내 tsconfig.json에 ES5를 대상으로 시도 할 경우, 사전 렌더링 서버는이 오류가 발생합니다 :Angles2/Typescript/Webpack 프리즘 Es6 오류
ReferenceError: Can't find variable: Map
undefined:1521 in KeyRegistry
:1540
:7
I합니다 (files
배열의 node_modules/typescript/lib/lib.es6.d.ts
포함) ES6를 대상으로 시도하는 경우는 사전 렌더링 서버는이 오류가 발생합니다 :
SyntaxError: Unexpected token 'const'
http://localhost:3000/app.js:50 in eval
http://localhost:3000/app.js:50
http://localhost:3000/app.js:20 in __webpack_require__
http://localhost:3000/app.js:40
나는이 일을하기 위해 일종의 polyfill을 포함해야한다고 생각하지만 포함 할 내용이나 포함 할 위치가 무엇인지 알지 못합니다.
는var webpack = require('webpack');
var path = require('path');
var rootDir = path.resolve();
module.exports =
{
target: 'node',
entry: rootDir + "/dist/client/app/bootstrap.js",
output: {
path: rootDir + "/dist/client", publicPath: '/', filename: "app.js",
pathinfo: true
},
devtool: 'eval',
resolve: {
root: rootDir + "/dist/client/app",
extensions: ['', '.js']
},
module: {
loaders: [
{
test: /\.ts/, loaders: ['ts-loader'], exclude: /node_modules/
}
]
}
};
그리고 도움이 경우 내 클라이언트 tsconfig : : 내 웹팩 설정을 변경하는 경우
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
"outDir": "../../dist/client",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true
},
"files": ["app/bootstrap.ts", "app/vendor.ts", "app/Window.ts", "tests/index.ts", "../../node_modules/typescript/lib/lib.es6.d.ts"]
}
업데이트
web
을 대상으로
여기에 도움이 경우 내 웹팩 설정입니다 node
대신 server.use(prerender.removeScriptTags());
을 미리 렌더링 서버에 기록하면 요청이 매 시간마다 사전 렌더링 서버에 도달하고 n 오류는 던져 지지만 아무 것도 미리 렌더링되지 않습니다. 이전보다 더 가까이에서 보였으므로 업데이트 할 것이라고 생각했습니다.
업데이트
프리렌더는 각도 코드를 실행하지 않는 것 같습니다. 내 index.html을에서 머리에 스크립트 태그에 window.prerenderReady = false
을 설정 한 다음 true로 설정하려고하면 다시는 내 루트 구성 요소가 인스턴스화 될 때, 밖으로 사전 렌더링 서버 시간 :
import { Component, OnInit } from '@angular/core'
@Component({
selector: 'my-app',
template: `
<div id="main"> all the things </div>
`
})
export class AppComponent implements OnInit
{
constructor(){}
ngOnInit()
{
// Prerender never executes this code before it times out
window.prerenderReady = true;
console.info('Prerender Ready');
}
}
오류가 밖으로 실패하고 페이지를 렌더링 중지 (기본 렌더링 엔진) PhantomJS을 방지하는 자바 스크립트하는 것 같은데 :). Map에 polyfill을 포함 시켰습니까? 'removeScriptTags'는 페이지 렌더링이 끝난 후에 스크립트 태그를 제거하기 때문에 렌더링과 관련이 없어야합니다. –
내 webpack 구성에서 '노드'대신 '웹'을 대상으로 삼아 사전 렌더링 es6 오류가 발생했습니다. 프리 렌더 서버는 200을 반환하지만 Angular 코드는 실행되지 않습니다. – MyCompassSpins
이에 대한 답변을 얻을 수있는 다른 정보가 있습니까? – MyCompassSpins