使用 angular 9 和它的新编译引擎 IVY,我的 CI 构建时间大幅增加。这当然是因为ngcc它在许多模块上运行。
例如
Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
...
Run Code Online (Sandbox Code Playgroud)
我以为ngcc缓存在编译的库node_modules,但我的node_modules缓存在我的CI工作,还有编的现象发生,所以这是不可能的。
我应该缓存什么路径以避免ngcc在每次构建时重新编译所有模块?
continuous-integration circleci angular angular-ivy angular9
我的文件app.spec.ts中有此导入:
import app from './app';
Run Code Online (Sandbox Code Playgroud)
导致此Typescript错误的原因
2:17 error Unable to resolve path to module './app' import/no-unresolved
Run Code Online (Sandbox Code Playgroud)
./app.ts确实存在,但是我还没有将.ts文件编译成.js文件。一旦将.ts文件编译为.js,错误就会消失。
但是,由于eslint应该使用typescript,因此应该使用.ts而不是.js解析模块。
我还在eslint配置文件中添加了打字稿信息:
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
Run Code Online (Sandbox Code Playgroud)
如何配置eslint,使其尝试使用.ts而不是.js解析模块?
干杯!
编辑#1
内容app.ts:
import bodyParser from 'body-parser';
import express from 'express';
import graphqlHTTP from 'express-graphql';
import { buildSchema } from 'graphql';
const app = express();
const schema = buildSchema(`
type Query {
hello: String
}
`);
const root = { hello: () => 'Hello world!' }; …Run Code Online (Sandbox Code Playgroud) 在我的项目的根目录,我有一个frontend和backend文件夹.两个文件夹都包含package.json列出其依赖项的文件夹.npm install在部署应用程序时,如何告诉Heroku 在两个文件夹上运行?Heroku似乎希望package.json默认情况下只有一个文件.我是否必须使用Procfile执行某些操作?Heroku文档似乎没有说明我的具体问题.
谢谢您的帮助!
由于没有模板,在指令中监听子元素事件的最佳方法是什么?有可能HostListener吗?如果没有,还有其他方法吗?
还有这个类似的问题:如何从Angular2中的父指令监听子事件,但建议的方法不能解决我的问题,因为我的指令和子元素不在同一个模板中(指令在主机上).
干杯!
编辑#1
这就是我目前正在做的事情(必须有更好的方法):
首先注入ElementRef我的指令:
constructor(private elView: ElementRef) {}
Run Code Online (Sandbox Code Playgroud)
然后用jQuery(或普通的JS)绑定:
$(this.elView.nativeElement)
.on('drag', '#childId', this.slide.bind(this))
Run Code Online (Sandbox Code Playgroud) 我正在循环一组模型,并希望每个模型显示一个元素.但是,出于CSS的原因,我必须在到达第四个模型时添加另一个元素(我需要clearfix为布局添加一个Bootstrap 元素才能看起来很好).
<div class="jumbotron">
<ol class="row">
<li *ngFor="#card of deck; #i = index" class="col-xs-3">
<h3>{{ card.name }}</h3>
</li>
</ol>
</div>
Run Code Online (Sandbox Code Playgroud)
怎么说,如果(i + 1) % 4 === 0,然后li加上另一个<li class="clearfix"></li>?
我的 中有以下调试配置launch.json:
{
"type": "node",
"request": "attach",
"preLaunchTask": "npm: start",
"name": "Attach",
"port": 9090
}
Run Code Online (Sandbox Code Playgroud)
这是在tasks.json以下定义的任务:
{
"type": "npm",
"script": "start",
"isBackground": true
}
Run Code Online (Sandbox Code Playgroud)
npm start 做这个: node --inspect=9090 ./src/server.js
如果我删除preLaunchTask调试配置,手动启动任务,然后启动调试会话,一切正常(调试会话附加节点进程)。
但是,使用preLaunchTask,我在启动调试后约 10 秒收到此错误:“无法跟踪指定的任务”。
似乎该任务在设置为 时可能需要一个问题匹配器isBackground,因此我也尝试了此任务配置但没有成功:
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"background": {
"activeOnStart": true,
"beginsPattern": "^.*Using environment.*",
"endsPattern": "^.*listening.*"
}
}
}
Run Code Online (Sandbox Code Playgroud)
的输出 npm: start
5:13:12 PM web.1 | Using environment: production
5:13:12 PM web.1 …Run Code Online (Sandbox Code Playgroud) 我有一个使用MediaRecorderapi 创建的音频文件/ blob :
let recorder = new MediaRecorder(this.stream)
let data = [];
recorder.ondataavailable = event => data.push(event.data);
Run Code Online (Sandbox Code Playgroud)
然后在录制结束时:
let superBlob = new Blob(data, { type: "video/webm" });
Run Code Online (Sandbox Code Playgroud)
如何使用此blob创建AudioBuffer?我需要:
Blob对象转换为ArrayBuffer我可以使用的对象AudioContext.decodeAudioData(返回一个AudioBuffer)或Blob对象转换为a Float32Array,我可以将其复制到AudioBufferwith中AudioBuffer.copyToChannel()任何关于如何实现这一点的提示都表示赞赏.干杯!
Typescript在此导入中找不到该模块import ga from 'googleAnalytics';
SystemJS知道在哪里找到模块,因为它已被映射到前面,如下所示:
map: {
'@angular': 'node_modules/@angular',
'rxjs': 'node_modules/rxjs',
'underscore': 'node_modules/underscore/underscore-min.js',
'googleAnalytics': '//www.google-analytics.com/analytics.js'
},
Run Code Online (Sandbox Code Playgroud)
我怎样才能提供类似的映射tsc?
这个问题似乎指向了一个很好的方向:如何在Angular 2中避免使用非常长的相对路径进口?
Typescript 2.0似乎支持paths配置tsconfig.json.有没有办法下载Typescript 2.0?我可以为path配置提供一个http url(//www.google-analytics.com/analytics.js),就像我在使用SystemJS一样吗?如果没有办法下载Typescript 2.0,我怎么能用当前版本实现我想要的?
编辑
我得到的具体错误是:"找不到模块'ga'".
这是我的tsconfig.json:
{
"compilerOptions": {
"rootDir": "./",
"target": "es5",
"module": "system",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true
},
"exclude": [
"node_modules",
"front-end/node_modules",
"typings/main",
"typings/main.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud) 我可以轻松地获得具有多个值的导出默认值:
class Car {...}
class Bus {...}
export default { Car, Bus }
Run Code Online (Sandbox Code Playgroud)
我还可以轻松获得某种类型的导出默认值
export default interface Airplane {...}
Run Code Online (Sandbox Code Playgroud)
但我不能默认导出多种类型
interface Airplane {...}
interface Motorcycle {...}
// 'Airplane' only refers to a type, but is being used as a value here. ts(2693)
export default { Airplane, Motorcycle }
Run Code Online (Sandbox Code Playgroud)
或者多种类型和值的混合。
class Car {...}
interface Motorcycle {...}
// 'Airplane' only refers to a type, but is being used as a value here. ts(2693)
export default { Car, Airplane }
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这个目标?
本文提到
常春藤为未来打开了一些可能性。现在应该可以在没有zone.js的情况下运行应用程序,并以半手动方式处理变更检测(有点像使用React一样)。这些API已经存在,但只是实验性的,没有记录在案,并且可能会在不久的将来发生变化。
我认为已经可以在Ivy之前运行没有zone.js的应用程序了。常春藤是否允许半手动处理变更检测?这些实验性API在哪里?有文件吗?常春藤仍然使用zone.js吗?
我的目标是通过手动触发更改检测来将更改检测降至最低。这样做的最佳选择是什么。特别是使用常春藤时最好的选择是什么。
angular ×4
typescript ×3
angular-ivy ×2
angular9 ×1
audiobuffer ×1
blob ×1
circleci ×1
deployment ×1
dyno ×1
es6-modules ×1
eslint ×1
heroku ×1
node.js ×1
procfile ×1
systemjs ×1
tsc ×1
tsconfig ×1
zone ×1