安装angular
1.nodejs
2.npm
3.typescript
4.angular
项目初始化
1. mkdir test
2. mkdir src
3. npm -y init
4.src/hello.js
5.npm install --save-dev jshint
6. .jshintrc
{
"browser": true,
"browserify": true,
"devel": true
}
7.package.json
"scripts": {
"lint": "jshint src"
}
8.npm run lint
单元测试
1. npm install --save-dev jasmine-core sinon
Jasmine: 单元测试框架
Sinon: 测试库
2. npm install --save-dev karma karma-jasmine karma-jshint-preprocessor
Karma: test runner
3. npm install --save-dev phantomjs karma-phantomjs-launcher
Phantom: 浏览器运行环境
4. karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
files: [
'src/**/*.js',
'test/**/*_spec.js'
],
preprocessors: {
'test/**/*.js': ['jshint'],
'src/**/*.js': ['jshint']
},
browsers: ['PhantomJS']
})
}
5. .jshintrc
{
"browser": true,
"browserify": true,
"devel": true,
"globals": {
"jasmine": false,
"describe": false,
"it": false,
"expect": false,
"beforeEach": false,
"afterEach": false
}
}
6. package.json
"scripts": {
"lint": "jshint src test",
"test": "karma start"
}
7. npm run lint
npm run test
项目模块化
1. browserify && refer plugins
npm install --save-dev browserify karma-browserify
Lodash && jQuery
1. npm install --save lodash jquery