Skip to content

Commit ee7da62

Browse files
committed
add webpack
1 parent 2770cd7 commit ee7da62

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

gulpfile.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const gulp = require("gulp"),
2+
path = require('path'),
3+
watch = require('gulp-watch'),
4+
uglify = require('gulp-uglify'),
5+
concat = require('gulp-concat'),
6+
plumber = require('gulp-plumber'),
7+
del = require('del'),
8+
runSequence = require('run-sequence'),
9+
exec = require('child_process').execSync;
10+
11+
/**
12+
* File Path
13+
*/
14+
const ROOT = __dirname;
15+
const SRC_PATH = path.join(ROOT, './lib');
16+
const PUBLIC_PATH = path.join(ROOT, './public');
17+
const DIST_PATH = path.join(ROOT, './dist');
18+
19+
const JS_PUBLIC_FILES = path.join(PUBLIC_PATH, './**/*.js');
20+
21+
// Clean Task
22+
gulp.task('js.build', function(callback) {
23+
exec('num run webpack', function(err, stdout, stderr) {
24+
if (err) { console.log(err); }
25+
26+
callback();
27+
});
28+
});
29+
30+
// JavaScript
31+
gulp.task('js.copy', function() {
32+
return gulp.src([JS_PUBLIC_FILES])
33+
.pipe(gulp.dest(DIST_PATH));
34+
});
35+
36+
// ファイル更新監視
37+
gulp.task('watch', function() {
38+
});
39+
40+
/**
41+
* Build Task
42+
**/
43+
gulp.task('build.js', function(callback) {
44+
return runSequence(
45+
'js.build',
46+
'js.copy',
47+
callback
48+
);
49+
});
50+
51+
/**
52+
* Dist Task
53+
**/
54+
gulp.task('dist', function(callback) {
55+
return runSequence(
56+
'build.js',
57+
callback
58+
);
59+
});
60+
61+
/**
62+
* default Task
63+
**/
64+
gulp.task('default', function(callback) {
65+
runSequence(
66+
'watch',
67+
callback
68+
);
69+
});

lib/index.ts

Whitespace-only changes.

package.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
"apb": "index.js"
77
},
88
"scripts": {
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test": "$(npm bin)/mocha test/** -r test/spec_setup.js",
10+
"test:watch": "$(npm bin)/mocha -w test/** -r test/spec_setup.js",
11+
"start": "concurrently \"npm run webpack:w\" \"gulp\"",
12+
"webpack": "webpack",
13+
"webpack:w": "webpack --progress --colors --watch",
14+
"build": "concurrently \"webpack --config ./webpack.production.config.js --progress --profile --colors\" \"gulp dist\""
1015
},
1116
"repository": {
1217
"type": "git",
@@ -21,6 +26,26 @@
2126
],
2227
"author": "daisuke.takayama",
2328
"license": "MIT",
29+
"devDependencies": {
30+
"@types/node": "^7.0.14",
31+
"chai": "^3.5.0",
32+
"concurrently": "^3.4.0",
33+
"del": "^2.2.2",
34+
"gulp": "^3.9.1",
35+
"gulp-concat": "^2.6.1",
36+
"gulp-mocha": "^4.3.1",
37+
"gulp-plumber": "^1.1.0",
38+
"gulp-uglify": "^2.1.2",
39+
"gulp-watch": "^4.3.11",
40+
"jsdom": "^10.0.0",
41+
"path": "^0.12.7",
42+
"power-assert": "^1.4.2",
43+
"run-sequence": "^1.2.2",
44+
"ts-loader": "^2.0.3",
45+
"typescript": "^2.3.1",
46+
"typings": "^2.1.1",
47+
"webpack": "^2.4.1"
48+
},
2449
"bugs": {
2550
"url": "https://github.com/atomic-package/apb-cli/issues"
2651
},

webpack.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
var webpack = require('webpack');
3+
4+
module.exports = {
5+
entry: __dirname + "/lib/index.ts",
6+
output: {
7+
filename: "index.js",
8+
path: __dirname + "/public/"
9+
},
10+
module: {
11+
loaders: [
12+
{ test: /\.tsx?$/, loader: "ts-loader" },
13+
{ test: /\.html$/, loader: "html-loader?minimize=false" }
14+
]
15+
},
16+
resolve: {
17+
extensions: [".ts", ".tsx", ".js"]
18+
},
19+
plugins: [
20+
new webpack.DefinePlugin({
21+
'process.env': {
22+
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
23+
}
24+
})
25+
]
26+
};

webpack.production.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
var webpack = require('webpack');
3+
4+
module.exports = {
5+
entry: __dirname + "/lib/index.ts",
6+
output: {
7+
filename: "index.js",
8+
path: __dirname + "/dist/"
9+
},
10+
module: {
11+
loaders: [
12+
{ test: /\.tsx?$/, loader: "ts-loader" },
13+
{ test: /\.html$/, loader: "html-loader?minimize=false" }
14+
]
15+
},
16+
resolve: {
17+
extensions: [".ts", ".tsx", ".js"]
18+
},
19+
plugins: [
20+
new webpack.optimize.UglifyJsPlugin({
21+
compress: {
22+
warnings: false
23+
}
24+
})
25+
]
26+
};

0 commit comments

Comments
 (0)