在运行 npm install -g @angular/cli 后创建新的 angular 项目时,出现以下错误
npm 错误!解析 '...:"^2.1.0","ntypescrip' 附近时 JSON 输入意外结束
npm 错误!可以在以下位置找到此运行的完整日志:npm ERR!
C:\Users\Suraj\AppData\Roaming\npm-cache_logs\2019-06-28T06_04_16_049Z-debug.log 包安装失败,见上。
是否可以将 crossorigin 属性添加到由 angular cli 生成的脚本标签?
运行我的 angular 应用程序时,脚本标签被添加到我的 index.html 的末尾:
<script src="runtime-es2015.3d05cbd29d24231258bf.js" type="module"></script>
<script src="polyfills-es2015.28da6787754ec8436843.js" type="module"></script>
<script src="main-es2015.4106b7f4d43a05cb792d.js" type="module"></script>
是否可以配置 angular-cli,以便在构建 index.html 中包含这些标签时,将 crossorigin 属性添加到脚本声明中:
<script src="runtime-es2015.3d05cbd29d24231258bf.js" type="module" crossorigin="use-credentials"></script>
我为什么要问这个? 我的应用程序部署到使用基本身份验证的 apache 服务器。使用 Firefox 或 Edge(chrome 很好)时,对 javascript 模块的请求会收到 401 错误,因为未设置 Authorization 标头。如果添加了 crossorigin 标记,则设置 Authorization 标头。因此,如果我希望我的用户能够使用 FF 或 Edge,我需要能够添加该 crossorigin 属性。
感谢您阅读我的问题。
我成功为节点配置了eslint(npm run eslint);但我无法将 Angular-CLI 配置为在此配置中使用 eslint;它总是使用 tslint。
我搜索了各种在线资源,但只发现了一个提示,表明这可能根本不受支持。
有可能实现这一目标,还是我在这里坚持使用 tslint?
我正在执行ng serve,但在生成块后无法编译。
同一个存储库正在同事的机器上工作,具有相同的版本如下:
还试过:
npm i在强制清理 npm 缓存后尝试。执行的命令: ng serve
错误是:
ERROR in ./src/assets/css/style.css (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./src/assets/css/style.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
TypeError: Cannot read property 'type' of undefined
at /home/akashj/workspace/projects/frontEnd/src/assets/css/style.css:1999:3
at stringifyNode (/home/akashj/workspace/projects/frontEnd/node_modules/postcss-value-parser/lib/stringify.js:2:19)
at Function.stringify (/home/akashj/workspace/projects/frontEnd/node_modules/postcss-value-parser/lib/stringify.js:45:10)
at Gradient.colorStops (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/hacks/gradient.js:505:26)
at Gradient.oldWebkit (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/hacks/gradient.js:398:10)
at Gradient.replace (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/hacks/gradient.js:91:30)
at Gradient.add (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/value.js:148:20)
at Gradient.add (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/hacks/gradient.js:572:35)
at Gradient.process (/home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/prefixer.js:157:16)
at /home/akashj/workspace/projects/frontEnd/node_modules/autoprefixer/lib/processor.js:327:15
at /home/akashj/workspace/projects/frontEnd/node_modules/postcss/lib/container.js:190:18
at /home/akashj/workspace/projects/frontEnd/node_modules/postcss/lib/container.js:135:18
at Rule.each (/home/akashj/workspace/projects/frontEnd/node_modules/postcss/lib/container.js:101:16)
at Rule.walk …Run Code Online (Sandbox Code Playgroud) 我有一个混合的 AngularJS/Angular 应用程序,需要一些时间来完成迁移以完全成为一个 Angular 应用程序。当这个过程发生时,我想从以前的构建系统转移到使用 CLI 和 webpack 来管理所有旧的 AngularJS 脚本。这是可能的,因为我之前已经通过将我的所有脚本添加到该scripts部分,angular.json如下所示:
"scripts": [
"src/app/angularjs/app.js",
"src/app/angularjs/controllers/main.js",
"src/app/angularjs/services/someService.js",
"src/app/angularjs/controllers/someController.js"
],
Run Code Online (Sandbox Code Playgroud)
这运行良好,并且 CLI 通过ng serve并ng build根据需要继续为混合引导应用程序构建。我现在遇到的问题是手动列出我正在迁移的当前应用程序的每个文件并不理想。我有数百个脚本需要添加,我需要的是能够使用如下所示的通配符模式:
"scripts": [
"src/app/angularjs/**/*.js"
],
Run Code Online (Sandbox Code Playgroud)
问题是不支持我所知道的这种语法。该glob模式是支持的assets部分angular.json是在这里,但没有说明在scripts部分:https://angular.io/guide/workspace-config#assets-configuration
在该scripts部分中,我找不到类似的解决方案。它确实有一个扩展的对象 API,但没有什么能解决我可以告诉从此处列出的特定目录中选择所有 .js文件的问题:https : //angular.io/guide/workspace-config#styles-and-scripts-configuration
是否可以通过某种方式使用 glob 模式或类似的方法来选择该scripts部分目录的所有文件,angular.json这样我就不必手动列出数百个单独的.js文件?
我已经使用以下方法构建了 Angular 应用程序:
ng build --prod --named-chunks --output-hashing=none
它按预期输出module-A.js,module-B.js但有一些文件,如default~<view1>~<module-1>~123xzy.js. (在 runtime.js 中这些默认文件是必需的)
我想分开module-A.js到另一个域,但我也必须移动default~<view1>~<module-1>~123xzy.js,所以它也会影响view1。
我怎样才能删除这样的default~<view1>~<module-1>~123xzy.js?即配置组合default~<view1>~<module-1>~123xzy.js成module-A.js?(而且我不想重构所有结构代码来消除此类文件,还有其他更轻松的方法吗?)
我想ng test在运行受影响的项目时将一些参数传递给命令(用于 CI 目的)。
例如:ng test --codeCoverage=true --watch=false --progress=false。
怎么能通过nx affected:test呢?
尝试过nx affected --help,但它不包含此类信息。
作为一个简单的解决方案,我可以编写自定义节点脚本,执行并获取结果,nx print-affected 然后从此结果运行命令,但我想找到更有效的方法。
我正在使用 Angular 8.2,并ts-nameof为我的项目安装了4.2.2,并ts-patch在全球安装了1.0.5。
我运行ts-patch install并ts-patch check显示:
Checking TypeScript v3.5.3 installation in [...]
[+] tsc.js is patched with ts-patch version 1.0.5.
[+] tsserverlibrary.js is patched with ts-patch version 1.0.5.
[+] typescript.js is patched with ts-patch version 1.0.5.
[+] typescriptServices.js is patched with ts-patch version 1.0.5.
Run Code Online (Sandbox Code Playgroud)
因此,我将ts-patch示例部分中的以下内容添加到了我的tsconfig.json:
{
"compilerOptions": {
"plugins": [
{ "transform": "ts-nameof", "type": "raw" }
]
}
}
Run Code Online (Sandbox Code Playgroud)
并跑了ng serve -o。
还在抱怨Cannot find …
我的问题是否可以扩展架构属性?
我试过的:
collection.json
{
"$schema": "http://schema.angular.io/schematics/collection/2",
"name": "@my/schematics",
"description": "my default collection, containing all schematics that are used normally",
"schematics": {
"library": {
"extends": "@nrwl/angular:library", <--- extends nrwl library
"aliases": [ "lib" ],
"factory": "./library",
"description": "Create my library.",
"schema": "./library/schema.json"
}
}
Run Code Online (Sandbox Code Playgroud)
图书馆/schema.json
{
"$schema": "http://schema.angular.io/schematics/collection/2",
"id": "SchematicsAngularLibrary",
"title": "Create my library",
"type": "object",
"properties": {
"legacy": { <--- adds custom property
"type": "boolean",
"description": "Legacy mode",
"default": false
}
},
"required": []
}
Run Code Online (Sandbox Code Playgroud)
和我的简化原理图库/index.ts
import { chain, externalSchematic, …Run Code Online (Sandbox Code Playgroud) angular-cli ×10
angular ×9
javascript ×3
angular9 ×1
eslint ×1
monorepo ×1
npm ×1
nrwl ×1
nrwl-nx ×1
typescript ×1
webpack ×1