From 8be5e12289401ed3190bffd91bf9e8b5ed5bda51 Mon Sep 17 00:00:00 2001 From: d3viant0ne Date: Sat, 6 Aug 2016 02:48:48 -0500 Subject: [PATCH] chore(build): Reworks babel build * 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 ) --- .gitignore | 2 +- .npmignore | 13 ------- gulpfile.js | 71 +++++++++++++++++++++++++++++++++++++++ index.js | 5 +++ package.json | 21 +++++++++--- scripts/release/README.md | 2 +- webpack.config.babel.js | 47 -------------------------- 7 files changed, 94 insertions(+), 67 deletions(-) delete mode 100644 .npmignore create mode 100644 gulpfile.js create mode 100644 index.js delete mode 100644 webpack.config.babel.js diff --git a/.gitignore b/.gitignore index 9c628283..7079b996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules coverage -dist +lib diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 211cc091..00000000 --- a/.npmignore +++ /dev/null @@ -1,13 +0,0 @@ -example -scripts -src -test -.github -.gitattributes -.babelrc -.editorconfig -.eslintignore -.eslintrc -.travis.yml -CONTRIBUTING.md -webpack.config.babel.js diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..4822bd90 --- /dev/null +++ b/gulpfile.js @@ -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() +})) diff --git a/index.js b/index.js new file mode 100644 index 00000000..a293269e --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +module.exports = require('./lib/karma-webpack') diff --git a/package.json b/package.json index 956ff846..9135337a 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/scripts/release/README.md b/scripts/release/README.md index 6c61a7ca..40714bda 100644 --- a/scripts/release/README.md +++ b/scripts/release/README.md @@ -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. diff --git a/webpack.config.babel.js b/webpack.config.babel.js deleted file mode 100644 index ba36ee65..00000000 --- a/webpack.config.babel.js +++ /dev/null @@ -1,47 +0,0 @@ -import path from 'path' -import {optimize} from 'webpack' -import {name, dependencies, devDependencies} from './package.json' - -const {UglifyJsPlugin} = optimize - -const rootPath = (nPath) => path.resolve(__dirname, nPath) -const BUILD_PATH = './dist' -const NODE_MODULES = rootPath('node_modules') -const IS_BUILD = process.env.NODE_ENV === 'production' - -const CONFIG = { - entry: './src/karma-webpack.js', - target: 'node', - - output: { - path: BUILD_PATH, - filename: 'karma-webpack.js', - library: name, - libraryTarget: 'umd' - }, - - module: { - loaders: [{ - test: /\.json/, - loader: 'json' - }, { - test: /\.js/, - loader: 'babel', - exclude: [NODE_MODULES], - query: {compact: true} - }] - }, - - externals: Object.keys(dependencies) - .concat(Object.keys(devDependencies)) -} - -if (IS_BUILD) - CONFIG.plugins = [ - new UglifyJsPlugin({ - comments: false, - sourceMap: false - }) - ] - -export default CONFIG