如何使用NPM所需文件的最小启动Angular2项目? [英] How to start Angular2 project with minimum of required files using npm?

查看:167
本文介绍了如何使用NPM所需文件的最小启动Angular2项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面Angular2快速启动和使用节点包管理器安装所需的库: https://开头angular.io/docs/ts/latest/quickstart.html

I was following Angular2 quickstart and installed required libraries using Node package manager: https://angular.io/docs/ts/latest/quickstart.html

创建的package.json:

created a package.json:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
  }

执行的

npm install

但NPM install命令下​​载大量文件,比如node_modules \\ angular2为32MB(可能是原料来源和其他的东西包括在内?),allthough
index.html的只需要其中的几个和实例angular2.dev.js只有1MB:

But npm install command downloads a lot of files for instance "node_modules\angular2" is 32MB (probably raw sources and other stuff included?), allthough index.html requires only few of them and for instance angular2.dev.js is only 1MB:

<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>

我想是快速启动项目并不需要这么多的磁盘空间。
有没有办法告诉NPM只下载捆绑或最小化的版本,还是有办法的包装进行生产时,优化node_modules目录?

I would like that quickstart project doesn't take this much disk space. Is there a way to tell npm to download only "bundles" or minimized versions, or is there a way to optimize node_modules directory when packaging for production?

推荐答案

您可以使用这些文件的CDN版本,并在开发中使用node_modules,不包括他们的生产都​​:

You can use the cdn versions of those files and use node_modules in development and don't include them in production at all:

<script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>

看看这个问题和答案的评论:
Angular2要求

另外这是你可以逃脱(取决于你的设置)最小的package.json:

Also this is the smallest package.json you can get away with (depending in your setup):

{
    依赖:{
      angular2:2.0.0-beta.0
      systemjs:0.19.6
    }
  }

我使用Webstorm这将启动自己的服务器,并编译自身的打字稿,当它检测到tsconfig.json文件。

I'm using Webstorm which starts its own server and compiles typescript on its own when it detects the tsconfig.json file.

所以,如果你没有自己的服务器,您需要添加的精简版服务器的依赖,配置和脚本,如果你没有一个TS编译器,你就必须添加打字稿依赖性和脚本还有:

So if you don't have your own server you'll need to add the lite-server dependency, config and scripts, and if you don't have a ts compiler you'll have to add the typescript dependency and scripts as well:

devDependencies:{
    打字稿:^ 1.7.3
  }

这篇关于如何使用NPM所需文件的最小启动Angular2项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆