angular2 基于webpack环境搭建
目录结构:
angular-quickstart
|_ ts
|_ app.ts
|_ index.ts
|_ index.html
|_ package.json
|_ tsconfig.json
|_ webpack.config.js
1. angular-quickstart/package.json
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "I will show you how to set up angular2 development angular-quickstart",
"keywords": [
"angular2",
"angular-quickstart"
],
"scripts": {
"start": "webpack-dev-server --devtool eval-source-map --progress --colors --hot --inline --watch --content-base",
"build": "webpack --progress --colors",
"dev": "webpack-dev-server"
},
"author": "Lin.keqing",
"license": "MIT",
"dependencies": {
"@angular/common": "^2.4.5",
"@angular/compiler": "^2.4.5",
"@angular/core": "^2.4.5",
"@angular/platform-browser": "^2.4.5",
"@angular/platform-browser-dynamic": "^2.4.5",
"@angular/forms": "^2.4.5",
"core-js": "^2.4.1",
"rxjs": "5.0.3",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@types/core-js": "^0.9.35",
"ts-loader": "^2.0.0",
"typescript": "^2.1.5",
"webpack": "^2.2.0",
"webpack-dev-server": "^2.2.0"
}
}
2. angular-quickstart/tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"moduleResolution": "node",
"noImplicitAny": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": false
},
"buildOnSave": false,
"compileOnSave": false,
"exclude": [
"node_modules"
]
}
3. angular-quickstart/webpack.config.js
const {resolve} = require('path');
module.exports = {
entry: {
index: './ts/index.ts'
},
output: {
path: resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: 'dist/'
},
module: {
exprContextCritical: false,
rules: [
{
test: /\.ts$/,
use: ['ts-loader']
}
]
},
resolve: {
extensions: [
'.js',
'.ts'
]
}
};
运行npm install
4. angular-quickstart/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>environment</title>
</head>
<body>
<!--这里引用我们的第一个component-->
<my-app></my-app>
<!--加载使用webpack编译后的bundle-->
<script type="text/javascript" src="/dist/bundle.js"></script>
</body>
</html>
5. angular-quickstart/ts/app.ts
import {Component} from '@angular/core';
//声明第一个Component
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 AppApple</h1>'
})
export class AppComponent { }
6. angular-quickstart/ts/index.ts
//不显示引入,你会得到"Uncaught reflect-metadata shim is required when using class decorators"的错误
import 'core-js/es6';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone'; //引入NgModule装饰器
import { NgModule } from '@angular/core'; //引入浏览器模块
import { BrowserModule } from '@angular/platform-browser'; //引入启动器
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; //引入我们刚才创建的第一个component
import { AppComponent } from './app'; //声明一个应用模块
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
class AppModule { } //启动应用
platformBrowserDynamic().bootstrapModule(AppModule);
运行 npm start
完。
一个下下来就可以用的环境:
https://github.com/angular/quickstart
配套的学习地址:
http://angular2.axuer.com/docs/ts/latest/guide/learning-angular.html
angular2 基于webpack环境搭建的更多相关文章
- webpack 环境搭建
Webpack环境搭建 一.安装node 1.node官网下载node并安装----node里面内置了npm所以用在安装npm了 2.命令行输入node -v查看node是否安装成功 二.全局安装we ...
- TypeScript + Webpack 环境搭建
TypeScript + Webpack 环境搭建步骤 安装Node.js 安装npm 创建一个npm项目 安装typescript,配置ts 安装webpack,配置webpack 初始化一个npm ...
- 基于 Webpack 4 搭建 Vue 开发环境
自从工作之后,就已经很久没有写过博客了.时间被分割得比较碎,积累了一段时间的学习成果,才写下了这篇博客. 之前有写过 Webpack4 的文章,但是都比较偏入门,唯一的一篇实战篇 -- 基于Webpa ...
- Android开发之基于AndroidStudio环境搭建和工程创建
断断续续的学习安卓也有一段时间了.因为之前是搞iOS开发的, 之前有关iOS的博客请看<我的iOS开发系列博文>.<我的Objective-C系列文章>和<窥探Swift ...
- webpack环境搭建
环境搭建参考:Webpack+vue+element逐步搭建开发环境 webpack入门:http://www.jianshu.com/p/42e11515c10f ----------------- ...
- react+es6+webpack环境搭建以及项目入门
前言:拖了这么久,小菜鸟终于开始正式应用react,和es6来开发项目了.之前超喜欢同学的一个博客风格,这里贴一下地址:https://iwenku.net/,PC端是他很久之前做的,最近他重新做了一 ...
- webpack环境搭建开发环境,JavaScript面向对象的详解,UML类图的使用
PS:因为所有的设计模式都是基于面向对象来完成的,所以在讲解设计模式之前先来过一下面向对象都有哪些知识点 搭建开发环境 初始化npm环境 下载安装nodejs安装即可,nodejs自带npm管理包,然 ...
- node+webpack环境搭建 vue.js 2.0 基础学习笔记
npm install -g vue //全局安装vue npm install -g webpack //全局安装webpack npm install -g vue-cli //全局安装vue-c ...
- 基于ruby环境搭建Redmine
环境说明 系统版本 CentOS 6.9 x86_64 软件版本 ruby 2.4.4 rails 4.2 redmine-3.4.5 Redmine是一个开源的.基于Web的项目管理和缺 ...
随机推荐
- Xcode 中的main.m
在几乎所有的程序开发中程序一般都是从main函数开始运行的,那么IOS程序也不例外,在上图中我们可以看到Xcode为我们生成了一个main.m文件: // // main.m // iOS // // ...
- Trie 树内存消耗问题
大家都知道,Trie树(又称字典树)是一种树型数据结构,用于保存大量的字符串.它的优点是:利用字符串的公共前缀来节约存储空间. 相对来说,Trie树是一种比较简单的数据结构,比较易于理解.话说上帝是公 ...
- 几个重要的 ASM Disk Groups 参数
几个重要的Disk group 属性: 1. ACCESS_CONTROL.ENABLED该属性用来控制某个disk group 上ASM FILE Access Control. 该参数有2个值:t ...
- CF285 E Positions in Permutations——“恰好->大于”的容斥和允许“随意放”的dp
题目:http://codeforces.com/contest/285/problem/E 是2018.7.31的一场考试的题,当时没做出来. 题解:http://www.cnblogs.com/y ...
- DataGrid当列宽超出当前宽度时,没有数据也恒有滚动条
附件是DataGrid支持滚动条的文件. 具体使用如下: 1)DataGrid使用控件模板 <Setter Property="Template" Value="{ ...
- c# Linq Where 抛出异常 导致 程序崩溃
Collection was modified; enumeration operation may not execute" 这次项目中遇到一个问题, 就是C#程序随机崩溃, 抛出上面的异 ...
- POCO库中文编程参考指南(8)丰富的Socket编程
POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...
- 搭建Node+NPM+Grunt+Ruby开发环境
序 最近尝试了一下CoffeeScript,和Sass,不得不说这两个搭配起来的确是不错的选择,熟悉以后基本上开发就比较快速了. 当然要开发这个首先需要搭建环境,这里就需要有Node.NPM.Grun ...
- 转:在Linux上安装ant环境
1.从http://ant.apache.org 上下载tar.gz版ant 2.复制到/usr下 3.tar -vxzf apahce-ant-1.9.2-bin.tar.gz 解压 4.chow ...
- FZU2030 括号问题(dp)
Problem 2030 括号问题 Accept: 398 Submit: 753Time Limit: 1000 mSec Memory Limit : 32768 KB Proble ...