Skip to content

Commit

Permalink
chore(build): Reworks babel build
Browse files Browse the repository at this point in the history
* Add module export in project root
* Remove npmignore in favor of files array in package.json
* Adds minimal Gulp v4 build
  - clean
  - lint ( ESLint ./src )
  - build ( Babel transpile to ./lib )
  - watch ( Standard watch & rebuild )
  - default ( Cleans, lints & builds )
  • Loading branch information
joshwiens committed Aug 6, 2016
1 parent 77ba64c commit 8be5e12
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
coverage
dist
lib
13 changes: 0 additions & 13 deletions .npmignore

This file was deleted.

71 changes: 71 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const gulp = require('gulp')
const del = require('del')
const util = require('gulp-util')
const eslint = require('gulp-eslint')
const babel = require('gulp-babel')

gulp.task('clean', function(done) {
del([
'lib/**/*',
])
done()
})

/**
* Lints all the JavaScript in the project.
* Ignores transpiled code & node_modules.
*/
gulp.task('lint', function(done) {
gulp.src(['**/*.js', '!node_modules/**', '!lib/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
done()
})

/**
* Transpiles with Babel based on defined presets.
*/
gulp.task('build', function(done) {
gulp.src('src/**/*.js')
.pipe(babel({
presets: ['es2015', 'stage-2']
}))
.pipe(gulp.dest('lib'))
done()
})

/**
* Watches for changes in the src directory.
* "on change" transpiles incrementally.
* "on unlink" removes the transpiled version of the deleted file.
*/
gulp.task('watch', function() {
gulp.watch('src/**/*.js')
.on('change', function(path) {
gulp.src(path)
.pipe(babel({
presets: ['es2015', 'stage-2']
}))
.pipe(gulp.dest('lib'))
util.log(`File "${path}" rebuilt`)
})
.on('unlink', function(path) {
util.log(`File "${path}" removed`)
let filePathFromSrc = path.relative(path.resolve('src'))
let destFilePath = path.resolve('build', filePathFromSrc)

del.sync(destFilePath)
})
})

/**
* Entrypoint for running watch.
*/
gulp.task('build.watch', gulp.series('build', 'watch', function(done) {
done()
}))

gulp.task('default', gulp.series('clean', 'lint', 'build', function(done) {
done()
}))
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = require('./lib/karma-webpack')
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
"description": "Use webpack with karma",
"license": "MIT",
"homepage": "http://github.com/webpack/karma-webpack",
"main": "dist/karma-webpack.js",
"scripts": {
"lint": "eslint test src",
"gulp": "gulp",
"lint": "gulp lint",
"clean": "gulp clean",
"pretest": "npm run lint",
"test": "npm run test.unit",
"test.unit": "mocha --compilers js:babel-register --full-trace --check-leaks test/unit",
"test.integration": "npm run build && karma start --single-run",
"travis": "npm run test.unit && npm run test.integration",
"generate.changelog": "node scripts/release/generate-changelog.js",
"publish.version": "npm run build:dist && sh scripts/release/npm-publish.sh",
"build:dev": "webpack",
"build:dist": "cross-env NODE_ENV=production webpack"
"publish.version": "npm run build && sh scripts/release/npm-publish.sh",
"build:watch": "gulp build.watch",
"build": "gulp build"
},
"files": [
"lib",
"index.js"
],
"repository": {
"type": "git",
"url": "https://github.com/webpack/karma-webpack.git"
Expand Down Expand Up @@ -47,8 +52,14 @@
"conventional-changelog": "^1.1.0",
"cross-env": "^2.0.0",
"cz-conventional-changelog": "^1.1.6",
"del": "^2.2.1",
"eslint": "^3.1.1",
"eslint-plugin-babel": "^3.3.0",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-babel": "^6.1.2",
"gulp-eslint": "^3.0.1",
"gulp-util": "^3.0.7",
"gulp-watch": "^4.3.9",
"istanbul": "^0.4.4",
"json-loader": "^0.5.4",
"karma": "^1.x",
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

*The NPM Portion*
* `npm login` to the user with rights to publish to NPM
* `npm run publish.version` which executes a `dist` build and publishes using the tag created above.
* `npm run publish.version` which executes the build and publishes using the tag created above.
47 changes: 0 additions & 47 deletions webpack.config.babel.js

This file was deleted.

0 comments on commit 8be5e12

Please sign in to comment.