From 967d6566437d381252e02f7e09e3067a49764415 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 5 Jul 2015 13:14:28 -0400 Subject: [PATCH] Some updates to Node things. --- Gulpfile.coffee | 70 ++++++++++++++----------------------------------- package.json | 9 +++++-- 2 files changed, 26 insertions(+), 53 deletions(-) diff --git a/Gulpfile.coffee b/Gulpfile.coffee index 8180565..386c1fb 100644 --- a/Gulpfile.coffee +++ b/Gulpfile.coffee @@ -1,61 +1,29 @@ gulp = require('gulp') -browserify = require('browserify') -watchify = require('watchify') -coffeeReactify = require('coffee-reactify') glob = require('glob') path = require('path') source = require('vinyl-source-stream') spawn = require('child_process').spawn - -makeBrowserify = (file) -> - [sourcePath..., _, _] = file.split(path.sep) - target = sourcePath.concat(['js', 'app.js']).join(path.sep) - - b = browserify({ - entries: ['./' + file] - debug: true - extensions: ['.js', '.coffee', '.cjsx'] - paths: [path.join(path.sep)] - cache: {} - packageCache: {} - fullPaths: true - }).transform(coffeeReactify) - - bundle = b.bundle - - b.bundle = -> - console.log "Browserifying #{file}..." - - bundle - .call(b) - .pipe(source(path.basename(target))) - .pipe(gulp.dest(path.dirname(target))) - - b - -gulp.task 'watch', -> - gulp.watch './**/sass/app.scss', ['styles'] - glob '**/coffee/app.coffee', (err, files) -> - files.forEach (file) -> - b = watchify(makeBrowserify(file)) - b.on 'update', b.bundle - b.bundle() - -gulp.task 'styles', -> - glob '**/sass/app.scss', (err, files) -> - files.forEach (file) -> - [sourcePath..., _, _] = file.split(path.sep) - appPath = sourcePath.join(path.sep) - child = spawn 'bundle', [ - 'exec', 'compass', 'compile', - appPath, file, '--css-dir', 'css' - ] - child.stdout.pipe(process.stdout) - child.stderr.pipe(process.stderr) +webpack = require('webpack') gulp.task 'scripts', -> - glob '**/coffee/app.coffee', (err, files) -> + glob './themes/**/coffee/app.coffee', (err, files) -> files.forEach (file) -> - makeBrowserify(file).bundle() + parts = file.split(path.sep) + context = path.resolve(parts.slice(0, -1).join(path.sep)) + entry = ['.'].concat(parts.slice(-1)).join(path.sep) + + outputPath = path.resolve(parts.slice(0, -2).concat(['js']).join(path.sep)) + + console.log context + console.log entry + console.log outputPath + + compiler = webpack( + entry: entry + context: context + output: + path: outputPath + filename: 'app.js' + ) gulp.task 'default', ['watch'] diff --git a/package.json b/package.json index c210a07..2700352 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "1.0.0", "description": "", "main": "index.js", - "engines": { "node": ">=0.12" }, + "engines": { + "node": ">=0.12" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -11,11 +13,14 @@ "license": "ISC", "dependencies": { "browserify": "^9.0.8", + "cjsx-loader": "^2.0.1", "coffee-reactify": "^3.0.0", "coffee-script": "^1.9.2", "glob": "^5.0.5", "gulp": "^3.8.11", + "node-libs-browser": "^0.5.2", "vinyl-source-stream": "^1.1.0", - "watchify": "^3.2.0" + "watchify": "^3.2.0", + "webpack": "^1.9.10" } }