From 7a0472abc9dbca398b6b89d5e7535f5735b4e402 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Wed, 12 Feb 2014 20:14:13 +0900 Subject: [PATCH] Starting to add WebPack support. --- .gitignore | 1 + Gruntfile.js | 39 +++++++++++++++++++++++++++++++++++++++ lib/cli.js | 3 +++ lib/roles/app.js | 31 +++++++++++++++++++++++++++++++ res/app/scripts/entry.js | 3 +++ res/app/views/index.jade | 4 +++- webpack.config.js | 17 +++++++++++++++++ 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 Gruntfile.js create mode 100644 res/app/scripts/entry.js create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index 24061420..4876a654 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /doc/*.png /rethinkdb_data/ /.env +/tmp diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..19a54599 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,39 @@ +module.exports = function (grunt) { + + require('load-grunt-tasks')(grunt) + + grunt.initConfig({ + jade: { + translate: { + options: { + data: { + debug: false, + files: { + 'tmp/html/all.html': ['views/**/*.jade'] + + } + } + } + } + }, + + nggettext_extract: { + pot: { + files: { + 'lang/po/template.pot': ['tmp/html/all.html', 'public/js/controllers/**/*.js'] + } + } + }, + + nggettext_compile: { + all: { + files: { + 'public/js/lang/translations.js': ['lang/po/*.po'] + } + } + } + }) + + grunt.registerTask('translate', ['jade:translate', 'nggettext_extract', 'nggettext_compile']) + grunt.registerTask('default', ['translate']) +} diff --git a/lib/cli.js b/lib/cli.js index 6acef33d..3ae64234 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -445,6 +445,9 @@ program , 'provider name (or os.hostname())' , String , os.hostname()) + .option('-w, --resources-watch' + , Boolean + , process.env.RESOURCES_WATCH) .action(function() { var log = logger.createLogger('cli') , options = cliutil.lastArg(arguments) diff --git a/lib/roles/app.js b/lib/roles/app.js index cff2d22e..03d071d1 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -17,6 +17,9 @@ var wireutil = require('../wire/util') var wirerouter = require('../wire/router') var dbapi = require('../db/api') +var webpackMiddleware = require("webpack-dev-middleware") +var webpack = require("webpack") + var auth = require('../middleware/auth') module.exports = function(options) { @@ -38,6 +41,34 @@ module.exports = function(options) { app.use('/static/lib', express.static(pathutil.resource('lib'))) app.use('/static', express.static(pathutil.resource('app'))) + // WebPack settings + app.use(webpackMiddleware(webpack( { + cache: true, + debug: true, + devtool: 'inline-source-map', + entry: pathutil.resource('app') + '/scripts/entry.js', + output: { + path: '/static/build/', + filename: 'bundle.js' + }, + resolve: { + modulesDirectories: [pathutil.resource('lib'), './../../node_modules'] + }, + loaders: [ + { test: /\.css$/, loader: 'style!css' }, + { test: /\.coffee$/, loader: 'coffee' } + ] + }), { + noInfo: false, + quiet: false, + lazy: false, + publicPath: '/static/build/', + // public path to bind the middleware to use the same as in webpack + stats: { + colors: true + } + })) + app.use(express.cookieParser(options.secret)) app.use(express.cookieSession({ key: options.ssid diff --git a/res/app/scripts/entry.js b/res/app/scripts/entry.js new file mode 100644 index 00000000..dd242d6d --- /dev/null +++ b/res/app/scripts/entry.js @@ -0,0 +1,3 @@ +//var angular = require('angular') + +console.log('An entry') diff --git a/res/app/views/index.jade b/res/app/views/index.jade index dbb057e4..3ea9bd1d 100644 --- a/res/app/views/index.jade +++ b/res/app/views/index.jade @@ -2,6 +2,8 @@ doctype html html head meta(charset='utf-8') + title STF body(ng-cloak) div(ng-view) - script(src='/static/lib/requirejs/require.js', data-main='static/scripts/main.js') + //script(src='/static/lib/requirejs/require.js', data-main='static/scripts/main.js') + script(src='/static/build/bundle.js') diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000..077533ce --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,17 @@ +module.exports = { + cache: true, + debug: true, + devtool: 'inline-source-map', + entry: './res/app/scripts/entry.js', + output: { + path: './res/app/build/', + filename: 'bundle.js' + }, + resolve: { + modulesDirectories: ['./res/lib', 'node_modules'] + }, + loaders: [ + { test: /\.css$/, loader: 'style!css' }, + { test: /\.coffee$/, loader: 'coffee' } + ] +} \ No newline at end of file