Skip to content

Commit 94ca3ce

Browse files
committed
init
1 parent 097856e commit 94ca3ce

File tree

11 files changed

+291
-0
lines changed

11 files changed

+291
-0
lines changed

config/karma.conf.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
// Karma configuration
3+
// Generated on Thu Mar 16 2017 08:23:56 GMT+0800 (SGT)
4+
let webpack = require('./webpack.test');
5+
6+
module.exports = function (config) {
7+
config.set({
8+
webpack,
9+
10+
// base path that will be used to resolve all patterns (eg. files, exclude)
11+
basePath: '',
12+
13+
14+
// frameworks to use
15+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
16+
frameworks: ['jasmine'],
17+
18+
19+
// list of files / patterns to load in the browser
20+
files: [
21+
{pattern: 'test/**/*.ts', watched: false}
22+
],
23+
24+
25+
// list of files to exclude
26+
exclude: [],
27+
28+
29+
// preprocess matching files before serving them to the browser
30+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
31+
preprocessors: {
32+
'test/**/*.ts': ['webpack']
33+
},
34+
35+
36+
// test results reporter to use
37+
// possible values: 'dots', 'progress'
38+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
39+
reporters: ['progress', 'mocha'],
40+
41+
42+
// web server port
43+
port: 9876,
44+
45+
46+
// enable / disable colors in the output (reporters and logs)
47+
colors: true,
48+
49+
50+
// level of logging
51+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
52+
logLevel: config.LOG_INFO,
53+
54+
55+
// enable / disable watching file and executing tests whenever any file changes
56+
autoWatch: true,
57+
58+
59+
// start these browsers
60+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
61+
browsers: ['PhantomJS'],
62+
63+
64+
// Continuous Integration mode
65+
// if true, Karma captures browsers, runs the tests and exits
66+
singleRun: false,
67+
68+
// Concurrency level
69+
// how many browser should be started simultaneous
70+
concurrency: Infinity
71+
})
72+
}

config/webpack.dev.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
2+
3+
module.exports = {
4+
devtool: 'cheap-source-map',
5+
entry: {
6+
'index': './src/index.ts'
7+
},
8+
output: {
9+
filename: 'dist/[name].js',
10+
sourceMapFilename: 'dist/[name].source.map',
11+
library: 'lib',
12+
libraryTarget: 'umd'
13+
},
14+
resolve: {
15+
extensions: ['.ts', '.js'],
16+
modules: ['node_modules']
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.ts$/,
22+
use: [
23+
{
24+
loader: 'awesome-typescript-loader'
25+
}
26+
],
27+
exclude: [/\.e2e\.ts$/]
28+
}
29+
]
30+
},
31+
plugins: [
32+
33+
],
34+
node: {
35+
global: true,
36+
process: false,
37+
crypto: 'empty',
38+
module: false,
39+
clearImmediate: false,
40+
setImmediate: false
41+
}
42+
};

config/webpack.prod.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
2+
3+
module.exports = {
4+
devtool: 'cheap-source-map',
5+
entry: {
6+
'index': './src/index.ts'
7+
},
8+
output: {
9+
filename: 'dist/[name].js',
10+
sourceMapFilename: '[name].source.map',
11+
library: 'lib',
12+
libraryTarget: 'umd'
13+
},
14+
resolve: {
15+
extensions: ['.ts', '.js'],
16+
modules: ['node_modules']
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.ts$/,
22+
use: [
23+
{
24+
loader: 'awesome-typescript-loader'
25+
}
26+
],
27+
exclude: [/\.e2e\.ts$/]
28+
}
29+
]
30+
},
31+
plugins: [
32+
new UglifyJsPlugin({
33+
beautify: false, //prod
34+
output: {
35+
comments: false
36+
}, //prod
37+
mangle: {
38+
screw_ie8: true
39+
}, //prod
40+
compress: {
41+
screw_ie8: true,
42+
warnings: false,
43+
conditionals: true,
44+
unused: true,
45+
comparisons: true,
46+
sequences: true,
47+
dead_code: true,
48+
evaluate: true,
49+
if_return: true,
50+
join_vars: true,
51+
negate_iife: false // we need this for lazy v8
52+
},
53+
}),
54+
],
55+
node: {
56+
global: true,
57+
process: false,
58+
crypto: 'empty',
59+
module: false,
60+
clearImmediate: false,
61+
setImmediate: false
62+
}
63+
};

config/webpack.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
resolve: {
3+
extensions: ['.ts', '.js'],
4+
modules: ['node_modules']
5+
},
6+
module: {
7+
rules: [
8+
{
9+
test: /\.ts$/,
10+
use: [
11+
{
12+
loader: 'awesome-typescript-loader',
13+
query: {
14+
sourceMap: false,
15+
inlineSourceMap: true,
16+
compilerOptions: {
17+
removeComments: true
18+
}
19+
}
20+
}
21+
]
22+
}
23+
]
24+
},
25+
node: {
26+
global: true,
27+
process: false,
28+
crypto: 'empty',
29+
module: false,
30+
clearImmediate: false,
31+
setImmediate: false
32+
}
33+
};

examples/example.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
let Calculator = require('../dist/index').Calculator;
4+
let cal = new Calculator();
5+
console.log(cal.add(2, 3), cal.multiply(5, 20));

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./config/karma.conf');

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "karma-webpack-typescript",
3+
"version": "0.0.1",
4+
"description": "A simple CLI starter for karma/webpack/typescript",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"test": "karma start"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/naivefun/karma-webpack-typescript.git"
12+
},
13+
"keywords": [],
14+
"author": "",
15+
"license": "ISC",
16+
"bugs": {
17+
"url": "https://github.com/naivefun/karma-webpack-typescript/issues"
18+
},
19+
"homepage": "https://github.com/naivefun/karma-webpack-typescript#readme",
20+
"devDependencies": {
21+
"@types/jasmine": "^1.3.2",
22+
"awesome-typescript-loader": "^3.1.2",
23+
"jasmine": "^2.5.3",
24+
"karma": "^1.5.0",
25+
"karma-jasmine": "^1.1.0",
26+
"karma-mocha-reporter": "^2.2.2",
27+
"karma-phantomjs-launcher": "^1.0.4",
28+
"karma-webpack": "^2.0.3",
29+
"typescript": "^2.2.1",
30+
"webpack": "^2.2.1"
31+
}
32+
}

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Calculator {
2+
add(a: number, b: number): number {
3+
return a + b;
4+
}
5+
6+
multiply(a: number, b: number): number {
7+
return a * b;
8+
}
9+
}

test/index.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Calculator } from '../src/index';
2+
3+
describe('[Calculator] example tests', () => {
4+
let calculator = new Calculator();
5+
6+
it('simple calculations', () => {
7+
expect(calculator.add(1, 5)).toEqual(6);
8+
expect(calculator.multiply(2, 10)).toEqual(20);
9+
expect(calculator.multiply(0, 11)).toEqual(0);
10+
expect(calculator.multiply(0, -11)).toEqual(-0);
11+
});
12+
});

tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"noImplicitAny": false,
6+
"sourceMap": false
7+
}
8+
}

webpack.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
switch (process.env.NODE_ENV) {
2+
case 'prod':
3+
case 'production':
4+
module.exports = require('./config/webpack.prod');
5+
break;
6+
case 'test':
7+
case 'testing':
8+
module.exports = require('./config/webpack.test');
9+
break;
10+
case 'dev':
11+
case 'development':
12+
default:
13+
module.exports = require('./config/webpack.dev');
14+
}

0 commit comments

Comments
 (0)