[英]Link to global node modules folder from Angular2 app
I wish to have a centralised Node modules folder (using npm update -g to save to C disk) instead of the usual local folder which is contained in the app, due to Angular2 CLI installing 125mb+ worth of Node modules in the local folder. 我希望有一个集中的Node模块文件夹(使用npm update -g保存到C盘)而不是应用程序中包含的常用本地文件夹,因为Angular2 CLI在本地文件夹中安装了125mb +的Node模块。
So in the typescript files we previously imported the angular core like so: 因此在我们之前导入角度核心的打字稿文件中,如下所示:
import { Component } from '@angular/core';
But obviously this doesnt work, is it possible to put a prefix or hard URL somewhere to tell the app to search in the global folder for the modules? 但显然这不起作用,是否可以在某处放置前缀或硬URL来告诉应用程序在全局文件夹中搜索模块?
Modify SystemJs
configuration (usually systemjs.config.js
file), so it maps @angular
to you centralized node_modules\\@angular
folder, instead of local one. 修改
SystemJs
配置(通常是systemjs.config.js
文件),因此它将@angular
映射到集中式node_modules\\@angular
文件夹,而不是本地文件夹。
var map = {
'app' : 'app',
'@angular' : 'C:/node_modules/@angular', // path to centralized repo
};
Here is what your systemjs.config file should be : 这是你的systemjs.config文件应该是:
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'src',
'@angular': 'global location'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
//can add as per your requirement
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
})(this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.