我用npm安装了一个新的库,到目前为止一直很好.现在我想将css导入到我的项目中,显然我不应该直接链接到该node_modules文件夹.那么,有一个简单的做法导入我的项目?我正在使用Angular CLI.
我有一个想法,但我不确定这是不是一个好主意 - 我考虑安装gulp/grunt然后需要那里的风格并将其输出vendor.css到我的项目中.它甚至可能吗?
我试图用业力做测试,但得到一个错误:
ERROR in ./src/test.ts
Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class.
This likely means you have several @ngtools/webpack packages installed. You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies.
Run Code Online (Sandbox Code Playgroud)
当我执行cmd时,我得到了这个结果:
+-- @angular/cli@1.1.1
| `-- @ngtools/webpack@1.4.1
`-- @ngtools/webpack@1.5.1
Run Code Online (Sandbox Code Playgroud)
在我,package.json我只有@ngtools/webpack": "^1.5.1
1.4.1来自哪里?
我需要使用Angular 4检查文件夹中是否存在图像.我有一个从服务器返回的图像名称列表.我需要的是检查资产文件夹中是否存在该图像.任何帮助或想法都会很棒.
我有一个Angular cli项目,该项目导入了我通过npm(npm packagr + npm pack)中的相对引用制作的UIcomponents库。之所以有效,是因为该应用程序是整体的,所有内容都在那里。
我的问题是:独立运行库进行开发,我需要BrowserModule和BrowserAnimationModule。这些只是使用Angular动画运行lib所必需的。
问题是您不能多次导入浏览器模块,因此当我现在在Angular应用程序中包含库时,该应用程序和库都将导入BrowserModule。解决此孤立问题的方法是,让任何不是appmodule import CommonModule导入的东西,但随后我必须将其更改回运行独立库。
任何帮助表示赞赏。
我想使用Nrwl Nx(一个项目中有多个应用程序;https://nrwl.io/nx)启动Angular项目,但是我有两个问题:
如何为不同的应用程序指定不同的版本号?通常,我在中给出一个版本号package.json,但是使用Nx时package.json,我所有的应用程序都只有一个。我应该把它放在环境文件中吗?还是在.angular-cli.json文件中?
我读到:“升级到lib需要更改所有实现者。” 是否有解决方案(绕过)在不同的应用程序中使用不同版本的lib或NPM软件包?只有一个node_modules,但这对我的应用程序至关重要。
如您所知,Nx项目的结构如下所示:
apps
app1
app2
libs
lib1
lib2
node_modules
package.json
.angular-cli.json
...
Run Code Online (Sandbox Code Playgroud)
也许这两个问题都是基于观点的(我不太确定那个问题),但是关于Nrwl Nx的文章很少,答案也可以帮助其他人。谢谢。
我有一个angular 4应用程序,我想在ubuntu上运行它。我将所有项目文件,package.json和package-lock.json复制到winscp中的文件夹,但没有复制node_modules!现在,当我运行npm install时,出现如下错误:
> node-sass@4.7.2 install /home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass
> node scripts/install.js
Unable to save binary /home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass/vendor'
at Object.fs.mkdirSync (fs.js:885:18)
at sync (/home/ubuntu/cms/node_modules/mkdirp/index.js:71:13)
at Function.sync (/home/ubuntu/cms/node_modules/mkdirp/index.js:77:24)
at checkAndDownloadBinary (/home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:111:11)
at Object.<anonymous> (/home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:154:1)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/home/ubuntu/cms/node_modules/@angular/cli/node_modules/node-sass/vendor' }
> node-sass@4.9.1 install /home/ubuntu/cms/node_modules/node-sass
> node scripts/install.js
Unable to save binary /home/ubuntu/cms/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, …Run Code Online (Sandbox Code Playgroud) APP_INITIALIZER在库模块中定义时,构建将失败并显示Lambda not supported错误.按照文档导出函数时抛出构建错误:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { MylibComponent } from './mylib.component';
export function myLibInit() {
return () => console.log('Hi from exported function');
}
@NgModule({
providers: [
{
provide: APP_INITIALIZER,
multi: true,
useFactory: myLibInit
}
]
})
export class MylibModule { }
Run Code Online (Sandbox Code Playgroud)
构建误差均投掷dev和prod.
我也尝试使用ES6对象方法简写符号来定义工厂函数:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { MylibComponent } from './mylib.component';
@NgModule({
providers: [
{
provide: APP_INITIALIZER,
multi: true,
useFactory() { …Run Code Online (Sandbox Code Playgroud) 是的,我发现了很多相似的东西,但我的实例仍未解决.我想避免杀死浏览器端的安全性,而是让代理完成它的工作,但我担心我在设置中遗漏了一些无聊的细节,我无论如何都不是CORS专家.
所以,我得到的...... 403;
Failed to load http://localhost:10000/some/rest/endpoint: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
其中localhost:10000是我的api url,:4200是默认的Angular CLI实例.
所以我配置了一个代理,因为我希望在angular.json中这样做;
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular-proj:build",
"proxyConfig": "./proxy.conf.json"
},
Run Code Online (Sandbox Code Playgroud)
并添加proxy.conf.json;
{
"/some/rest/*": {
"target": "http://localhost:10000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
Run Code Online (Sandbox Code Playgroud)
我提供它甚至标记CLI服务确认的proxy.conf;
[HPM] Proxy created: /some/rest -> http://localhost:10000 等等...
....除了我仍然得到403,仍然在Request*标题中看到;
Host: localhost:10000
Origin: http://localhost:4200
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我在这里错过了什么内容?我不想把所有来源的请求写成星号,而且我不想关闭浏览器检查,我更愿意将这个很好地捆绑在服务配置中,就像我这样做另外一对眼睛非常受欢迎.干杯
ADDENDUM …
似乎没有一种方法可以绑定到Angular CLI正在使用的任何工具来构建/服务网站。
我想运行自己的图像优化脚本,却找不到运行脚本和给定时间点或将代码添加到默认构建脚本的方法。
有没有推荐的/规范的方法来做到这一点?
Angular CLI提供了在构建项目时替换文件的可能性。我想使用此功能将默认样式的SCSS文件替换为包含客户特定CSS的SCSS文件。
但是Angular CLI似乎不能替换SCSS文件。我怎样才能做到这一点?
我尝试过的
environment.default.ts
export const environment = {
name: 'default'
};
Run Code Online (Sandbox Code Playgroud)
环境特殊
export const environment = {
name: 'special'
};
Run Code Online (Sandbox Code Playgroud)
默认/_scss-config.scss
@debug ('default'); // gets called but should never be called
Run Code Online (Sandbox Code Playgroud)
特殊的/_scss-config.scss
@debug ('special'); // never gets called
Run Code Online (Sandbox Code Playgroud)
angular.json(仅相关部分)
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"fileReplacements": [
{
"replace": "src/environments/environment.default.ts",
"with": "src/environments/environment.special.ts"
},
{
"replace": "src/scss/default/_scss-config.scss",
"with": "src/scss/special/_scss-config.scss"
}
],
"stylePreprocessorOptions": {
"includePaths": [
"src/scss/default"
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
主要
import …Run Code Online (Sandbox Code Playgroud) angular-cli ×10
angular ×8
node.js ×2
angularjs ×1
cors ×1
css ×1
ng-packagr ×1
node-sass ×1
npm ×1
nrwl ×1
package.json ×1
sass ×1
vendor ×1
webpack ×1