- Tìm số 0 đầu tiên trong một mảng bit
- Unix Hiển thị thông tin về các tập tin khớp với một trong hai mẫu
- Biểu thức chính quy thay thế nhiều tệp
- Ẩn lệnh từ xtrace
我一直在尝试使用 ngTools 在我的 Angular 应用程序中设置 AOT(使用 Webpack 进行模块加载),并且有一段时间绝对是噩梦。我已经浏览了文档中的各种资源 đâyVà đây以及通读 ngTools 自述文件,查看通过 this resource 找到的隐藏在 Angular CLI 中的示例(该应用程序不是用 Angular CLI 构建的,但我认为它至少是一个有用的引用)在 Angular + Webpack + Sass + ngTools 上(我也使用 SASS,但是用我的 webpack.config.aot.js 编译得很好 - 不过它确实阻止我切换到 ngc,至少就我发现的而言,这是我在一些示例中看到的),以及过去几天我发现的每个 github 问题或 stackoverflow 帖子,无论我尝试构建 aot 做什么都会产生以下错误:
ERROR in window is not defined
ERROR in /Users/nataliecoley/development/company-app-name/src/main-aot.ts (2,36): Cannot find module '../aot/src/app/app.module.ngfactory'.
ERROR in ./src/main-aot.ts
cửa sổ
没有出现代码中的任何地方)但如果有人知道这可能来自哪里(或者如果您认为它与错误 2 和 3 相关),我愿意接受建议。
app.module.ts
hiện hữu
main-aot.ts
之前没有被编译所以到时候
main-aot.ts
去编译它找不到文件。但是,我根据我专门找到的文档进行了设置,以便它已经被编译和
app.module.ngfactory
编译器到达时准备就绪
main-aot.ts
.
.
+-- config/
| +-- helpers.js
| +-- webpack.common.js
| +-- webpack.dev.js
| +-- webpack.prod.js
+-- src/
| +-- app/
| +-- assets/
| +-- vendor/
| +-- index.html
| +-- main.ts
| +-- main-aot.ts
| +-- polyfills.ts
| +-- tsconfig.json
+-- package.json
+-- server.js
+-- tsconfig-aot.json
+-- webpack.config.aot.js
+-- webpack.config.js (only contains: module.exports = require('./config/webpack.dev.js');)
"build:aot": "webpack --config webpack.config.aot.js",
在我的 package.json 中。至于相关的包版本,我在 4.1.0 上用于所有 angular 包,我正在使用
@ngtools/webpack v1.3.1
, Và
webpack v 2.3.3
Và
typescript v2.3.0
{
"Tùy chọn biên dịch": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"skipLibCheck": true,
"skipCodeGeneration": false,
"typeRoots": [
"../node_modules/@types/"
]
},
"files": [
"src/app/app.module.ts",
"src/main-aot.ts"
],
"compileOnSave": true,
"angularCompilerOptions": {
"genDir": "aot",
"entryModule": "src/app/app.module#AppModule",
"skipMetadataEmit": true
}
}
const ngtools = require('@ngtools/webpack');
const webpack = require('webpack');
const helpers = require('./config/helpers');
module.exports = {
devtool: 'source-map',
entry: {
main: './src/main-aot.ts'
},
resolve: {
extensions: ['.ts', '.js']
},
target: 'node',
output: {
path: helpers.root('dist'),
filename: 'build.js'
},
plugins: [
new ngtools.AotPlugin({
tsConfigPath: helpers.root('tsconfig-aot.json'),
entryModule: helpers.root('src', 'app', 'app.module#AppModule')
}),
new webpack.optimize.UglifyJsPlugin({ sourceMap: true })
],
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
},
{ test: /\.css$/, loader: 'raw-loader' },
{
test: /\.scss$/,
loaders: ['to-string-loader', 'style-loader', 'css-loader', 'resolve-url-loader', 'sass-loader?sourceMap']
},
{ test: /\.html$/, loader: 'raw-loader' },
{ test: /\.ts$/, loader: '@ngtools/webpack' }
]
}
}
tsconfig-aot.json
中。 ,不在
webpack.config.aot.js
里面,我见过的其他示例仅将其放在
webpack.config.aot.js
中.我只是在 tsconfig-aot.json 中尝试过它,只是
webpack.config.aot.js
以及以上两者 - 这些选项似乎都不能解决问题。我也试过编辑各种东西的文件路径(比如我的 tsconfig-aot.json 中的文件数组),以防我设置它以便它在错误的地方寻找我的文件并且无处可去。
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory';
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
1 Câu trả lời
请注意,来自您的资源:
I had some trouble with the path to the ngfactory code when compiling with ngc: Can't resolve './../path/to/app/app.module.ngfactory' This seems related to this issue. The solution for me was to define the genDir in the webpack config rather than the tsconfig.js file.
ngtools
为您完成所有这些,因为它旨在成为一个完整的黑盒 AOT 机制。您正在调和
ngc
(Ngay lập tức
ngfactory
代)与 Angular CLI 的 AOT 前端(
ngtools
).
ngfactories
您必须使用
ngc
构建您的应用程序.就个人而言,我使用 ngtools 进行开发构建,然后使用
ngc
以及 Angular Universal 服务器端渲染器。
ngtools
有一个使开发相当痛苦的错误 - 在第二次重新编译之前不会识别更改:
ngc
在生产构建中生成工厂......
"aot": "./node_modules/.bin/ngc -p tsconfig-aot.json",
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { renderModuleFactory } from '@angular/platform-server'
import { enableProdMode } from '@angular/core'
import { AppServerModuleNgFactory } from './dist/ngfactory/src/app/app.server.module.ngfactory'
import * as express from 'express';
import { readFileSync } from 'fs';
import { join } from 'path';
const PORT = process.env.PORT || 8081;
enableProdMode();
const app = express();
let template = readFileSync(join(__dirname, 'dist', 'index.html')).toString();
app.engine('html', (_, options, callback) => {
const opts = { document: template, url: options.req.url };
renderModuleFactory(AppServerModuleNgFactory, opts)
.then(html => callback(null, html));
});
app.set('view engine', 'html');
app.set('views', 'src')
app.get('*.*', express.static(join(__dirname, 'dist')));
app.get('*', (req, res) => {
res.render('index', { req });
});
app.listen(PORT, () => {
console.log(`listening on http://localhost:${PORT}!`);
});
关于Angular + AOT + Webpack + NgTools - 问题生成 ngFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43769503/
我正在尝试在项目中学习和添加 Angular 国际化。我只能理解 Angular 文档 (https://angular.io/guide/i18n-overview) 的编译时翻译。 我需要这样的东
在我的 Angular 应用程序中,基于登录用户,我想通过显示/隐藏不同的菜单项或允许/禁止某些路由来授予或限制功能。 目前成功登录后,我的 .NET Core API 会返回一个 JWT token
我是 Angular 的新手,目前我已经看过 angular.io 网站提供的一些示例。但是在component decorator在文档中的解释,它指出 Angular components are
这里是service employee-service.service.ts的代码 import { Injectable } from '@angular/core'; import { HttpC
我目前正在使用@angular/http URLSearchParams 类来检索 URL 参数。在 Angular 5 中,注意到这已被弃用,但我没有看到以我当前使用的方式替换 URLSearchP
我目前正在使用@angular/http URLSearchParams 类来检索 URL 参数。在 Angular 5 中,注意到这已被弃用,但我没有看到以我当前使用的方式替换 URLSearchP
如何正确安装 PUG/JADE 到 Angular 2 或更高版本 这样在工作和 AOT 和 JiT 的同时 工作单元和集成测试 并且在创建每个新组件时不会受到太多影响 最佳答案 我看到了很多解决方案
我的 Angular 12 应用程序中有一些通用组件,我计划将其创建为一个 Angular 库,以便其他应用程序也可以使用它。我们有一些应用程序在较低版本的 angular(例如 angular 8/
tl;dr; ng build 删除了包含我编译的自定义库的/dist 文件夹。这会使我项目代码中对该库的所有引用无效,从而导致 ng build 最终失败。我做错了什么? 我关注了documenta
我正在将一些“遗留”(非 typescript )js 库导入到我的 Angular SPA 中。 通常我只是从 cdn 添加一个负载到 index.html 就像: 在 Angular 分量中我只
我有这个 angular 应用程序,它基本上使用了库的概念。 我有 2 个名为 的库Lib1 和 lib2 根据他们所服务的微服务分组。 现在我将这些库导入主应用程序,即 应用1 事情一直到现在。 现
我在我的项目中启用了 angular Universal。我现在想完全删除它。我试图删除以下文件 /server.ts /webpack.server.config.js /src/tsconfig.
我已经有一个 AuthService 在登录时对用户进行身份验证,并且 AuthGuard 在未登录的情况下阻止访问。 某些页面我通过 UserProfile/Role 限制访问,但现在我需要阻止页面
我正在尝试使用 angular、TypeORM、SQLite 和其他组件作为 webpack 构建 Electron 应用程序。 我从在 GitHub 上找到的示例开始我的开发:https://git
我在从 Angular 8 更新到 9 并运行时遇到以下错误 ng 更新@angular/material: Package "@angular/flex-layout" has an incompa
我正在尝试使用 Angular 9,我想创建一个项目,然后创建一个库项目并开始向其中添加我想稍后在 GitHub 上发布的通用模块,并在我的本地使用这些库项目。 相关依赖如下: Angular CLI
我正在尝试使用 Angular 9,我想创建一个项目,然后创建一个库项目并开始向其中添加我想稍后在 GitHub 上发布的通用模块,并在我的本地使用这些库项目。 相关依赖如下: Angular CLI
我正在我的 h1 元素“之前”创建一个小的程式化三 Angular 形图案,但我无法正确地圆 Angular 。右上角没问题,但其他两个有剪裁问题。 这是输出以及形状的放大图像: 使用的代码如下: h
我有一个 Angular 元素,带有自定义标记名 - fancy-button。如何将 fancy-button 嵌入 Angular 应用程序? 我已经尝试了以下方法,但都没有用 - 在 index
我已将我的项目从 angular 5.2.9 升级到 angular 6.0.0-rc.5。 除了包路径中的几个快速 RxJS 修复外,一切看起来都不错。(此链接非常有用:Want to upgrad
Tôi là một lập trình viên xuất sắc, rất giỏi!