기본 콘텐츠로 건너뛰기

angular2 + webpack 개발

angular2 + webpack 개발

Angular2 + webpack

기본 npm package 준비

{ " name ": "angular2-test" , " version ": "1.0.0" , " description ": "" , " main ": "index.js" , " scripts ": { " test ": "echo \"Error: no test specified\" && exit 1" } , " author ": "" , " license ": "ISC" , " dependencies ": { " angular2 ": "^2.0.0-beta.15" , " bluebird ": "^3.3.5" , " core-js ": "^2.2.2" , " lodash ": "^4.11.1" , " reflect-metadata ": "^0.1.3" , " rxjs ": "^5.0.0-beta.6" , " zone.js ": "^0.6.11" } , " devDependencies ": { " awesome-typescript-loader ": "^0.17.0-rc.6" , " copy-webpack-plugin ": "^2.1.1" , " html-webpack-plugin ": "^2.15.0" } }

기본적으로 reflect-metadata , rxjs , zone.js 는 angular2 와 같이 설치되어야지 된다.

npm install rxjs --save npm install reflect-metadata --save npm install zone.js --save

typescript 설정

npm install typings --global

tsd 는 deprecated되었기 때문에 더이상 사용되지 않는다.

tsconfig.json

{ "compilerOptions" : { "target" : "es5" , "module" : "commonjs" , "emitDecoratorMetadata" : true , "experimentalDecorators" : true , "sourceMap" : true }, "exclude" : [ "node_modules" , "typings/main" , "typings/main.d.ts" , "bower_components" ] }

webpack 설정

기본적으로 다음 folder 구조를 따른다. (maven 과 유사)

├── dist ├── src │ ├── app │ └── public ├── package.json ├── tsconfig.json ├── typings.json └── webpack.config.js

src/app : javascript application

: javascript application src/public : html,css,image와 같이 static resource 구성

typescript 를 지원하기 위해서 awesome-typescript-loader 을 설치하고 loader에 다음과 같이 등록한다.

{ test: /\.ts$/ , loader: 'awesome-typescript-loader' , exclude: /node_modules/ }

webpack.config.js

'use strict' ; var webpack = require ( 'webpack' ); var HtmlWebpackPlugin = require ( 'html-webpack-plugin' ); var CopyWebpackPlugin = require ( 'copy-webpack-plugin' ); function buildConfig () { var isProd = false ; const config = { output: { path: __dirname + '/dist' , publicPath: isProd ? '/' : 'http://localhost:8080/' , filename: isProd ? '[name].[hash].js' : '[name].bundle.js' , chunkFilename: isProd ? '[name].[hash].js' : '[name].bundle.js' }, resolve: { extensions: [ '' , '.webpack.js' , '.web.js' , '.ts' , '.js' ], modulesDirectories: [ 'node_modules' ] }, devtool: 'cheap-source-map' , module : { loaders: [ { test: /\.ts$/ , loader: 'awesome-typescript-loader' , exclude: /node_modules/ } ] }, entry: { app: __dirname + '/src/app/app.ts' }, plugins: [ new webpack.NoErrorsPlugin(), new webpack.optimize.DedupePlugin(), new CopyWebpackPlugin([{ from: __dirname + '/src/public' }]), new HtmlWebpackPlugin({ template: './src/public/index.html' , inject: 'body' }) ] }; config.devServer = { contentBase: './dist' , stats: 'minimal' , outputPath: './dist' }; return config; } module .exports = buildConfig();

webpack에서 지정되는 entry point 가 된다. main.ts , bootstrap.ts 등 다양한 파일이름이 있지만, 개인적으로는 app.ts 가 가장 좋은것 같다.

app.ts 에서는 다음 세가지 기능을 한다.

router 의 등록 bootstrap 실행 첫페이지로 direction

/// import 'core-js/es6'; import 'core-js/es7/reflect'; import 'zone.js/dist/zone'; import { bootstrap } from 'angular2/platform/browser'; import { HTTP_PROVIDERS } from 'angular2/http'; import { enableProdMode } from 'angular2/core'; import { Component } from 'angular2/core'; import { provide } from 'angular2/core'; import { Router, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, LocationStrategy, Location, HashLocationStrategy } from 'angular2/router'; import { HeroService } from './hero.service'; import { DashboardComponent } from './dashboard.component'; import { HeroesComponent, HeroesRouterInfo } from './heroes.component'; import { HeroDetailComponent } from './hero-detail.component'; @RouteConfig([ { path: '/heroes', name: 'Heroes', component: HeroesComponent, }, HeroesRouterInfo, { path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true }, { path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent }, ]) @Component({ selector: 'my-app', template: ` {{title}} Dashboard Heroes `, styleUrls: ['app.component.css'], directives: [ROUTER_DIRECTIVES] }) class AppComponent { title: string; router: Router; location: Location; constructor(router: Router, location: Location) { this.title = 'This is Title'; this.router = router; this.location = location; } } // enableProdMode(); bootstrap(AppComponent, [ HTTP_PROVIDERS, ROUTER_PROVIDERS, provide(LocationStrategy, { useClass: HashLocationStrategy }), HeroService ]).catch(err => console.error(err));

위 app.ts 의 경우에는 router가 추가 되고, 여러 서비스 Provider들이 추가되는 것 이외에는 큰 차이가 없을것같다. 기본적으로 기존 angular 의 app.js 와 동일한 기능을 갖게 된다.

lodash 추가

typings install lodash --ambient --save

from http://netframework.tistory.com/449 by ccl(S)

댓글

이 블로그의 인기 게시물

[django] django rest framework 로그인 과정 | 장고 로그인 | 인증...

[django] django rest framework 로그인 과정 | 장고 로그인 | 인증... django 는 기능이 참 너무 많다 ^^; 지금은 서버는 django로, 프론트는 angular를 붙여서 간단한 웹을 만들어 보려고 한다. 웹 만들때 항상 회원가입/로그인 기능은 맨 앞에 구현한다. 어떻게 구현하면 좋을까... 찾아보다가 이 기능을 구현할 수 있는 방법이 너무 많아서 정보를 찾기 더 어려웠다. 일단 나는 django에서 django rest framework라는 것을 사용해서 API를 만드려고 한다. 순수 django 튜토리얼에는 바로 template 랑 연결해서 설명하는 부분이 많았다. 나는 그냥 API 만 만들고 싶다고!! 그래서 찾은 것이 django REST framework. https://www.django-rest-framework.org/api-guide/authentication django REST framework 설치 using pip pip install djangorestframework settings.py INSTALLED APPS 에 추가해야함 INSTALLED_APPS = [ ... 'rest_framework', ] django REST framework 에서도 인증 관련해서 제공하는 것이 1개가 아닌 여러 개다. 나는 그중에 TokenAuthentication을 이용해서 로그인을 구현해 보려고 한다. TokenAuthentication Token authentication is appropriate for client-server setups, such as native desktop and mobile clients. 이렇게 나와있어서 내가 하려는 것과 일치해서 이걸로 결정 ~ 솔직히 처음 로그인을 구현하려고 하면 도대체 그 과정이 어떻게 되는지 모를 수 도 있다. 나는 쉽게 정리하면 아래와 같은 과정이라고 생각한다. 로그인 로그아웃...

(주)레터플라이 채용 정보: 프로그래밍을 생각하면 가슴이 뛰는 개발자...

(주)레터플라이 채용 정보: 프로그래밍을 생각하면 가슴이 뛰는 개발자... Angular.js, Python, MySQL 중 한 가지 언어에 뛰어나신 분도 좋고 개발 업무 전반적으로 센스가 있으신 분도 환영합니다. 맡은 업무를 성실하게 수행해 나갈 수 있는 책임감과 태도를 갖고계신 분, 그리고 항상 새로운 방법론에 도전하고 포기를 모르는 분일수록 저희와 더욱 잘 맞을 것 같습니다. Angular.js, Python, MySQL 중 한 가지 언어에 뛰어나신 분도 좋고 개발 업무 전반적으로 센스가 있으신 분도 환영합니다. 팀 내 뛰어난 풀스택 개발자분들이 Angular.js, Python, MySQL 모두 작업 가능하시니 오셔서 함께 배우며 즐겁게 작업하시면 됩니다. 맡은 업무를 성실하게 수행해 나갈 수 있는 책임감과 태도를 갖고계신 분, 그리고 항상 새로운 방법론에 도전하고 포기를 모르는 분일수록 저희와 더욱 잘 맞을 것 같습니다. 개발 업무: 레터플라이의 핵심 기능인 편지, 사진을 제작하는 레터에디터, 포토에디터 개발. 이 기능들은 "모바일 웹을 통한 출력제품 생산 자동화 기술"(특허 출원 준비중)로서 레터플라이에서 자체개발했습니다. 근무 지역: 광화문역 5번출구 바로 앞 근무 환경: 책임과 존중을 중요시하는 수평적인 분위기, 도전적이며 서로에게 배우는 문화 근무 시간: 10-19시, 출근시간 자유 지정. 급여: 연봉/스톡옵션 협의 지원 방법: 팀 지원하기 더 많은 내용은 더 많은 내용은 더팀스 에서 확인하세요! from http://theteams.tistory.com/721 by ccl(A) rewrite - 2020-03-20 09:20:18

jqxGrid 정렬, 필터 메뉴 숨기기

jqxGrid 정렬, 필터 메뉴 숨기기 How I can remove filter to particular grid column - Angular, Vue, React, Web Components, Javascript, HTML5 Widgets Hi, I tried that it's working. I set properties to those columns as sortable: false, filterable: false. but when I clicked on the column one drop down is appearing with options "sort ascending", "sort descending", "remove sort" and those are all in disable www.jqwidgets.com from http://devesim.tistory.com/90 by ccl(A) rewrite - 2020-03-11 04:20:29