Skip to content

Commit

Permalink
Streamline build process a bit
Browse files Browse the repository at this point in the history
- vr.dev.js uses "eval" for debugging, so building should be slightly faster
- first steps towards a better deploy process
- removed some unnecessary dev dependencies
  • Loading branch information
brianchirls committed May 6, 2015
1 parent b198cca commit 2d2151d
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 42,562 deletions.
42,485 changes: 95 additions & 42,390 deletions build/vr.dev.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion build/vr.dev.js.map

This file was deleted.

33 changes: 17 additions & 16 deletions build/vr.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/vr.js.map

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
module.exports = (function () {
'use strict';

var extend = require('xtend');
var webpack = require('webpack');
var pkg = require('../package.json');

var banner = [
pkg.name + ' - ' + pkg.description,
'@version v' + pkg.version,
'@link ' + pkg.homepage,
'@license ' + pkg.license
].join('\n');

var common = {
entry: './src/entry.js',
module: {
preLoaders: [
{
test: /\.js$/,
exclude: /node_modules|bower_components|src\/lib/,
loader: 'jshint-loader'
}
],
loaders: [
{
test: /\.png$/,
loader: 'url-loader',
query: {
mimetype: 'image/png'
}
},
{
test: /\.jpg$/,
loader: 'url-loader',
query: {
mimetype: 'image/jpg',
limit: 8000,
name: 'image/[name].[ext]'
}
},
{ test: /\.css$/, loader: ['style', 'css'] }
]
},
resolve: {
modulesDirectories: ['web_modules', 'node_modules', 'bower_components']
},

//pretty strict
jshint: {
globals: {
__DEV__: true,
__ASSET_PATH__: true,
console: true
},

bitwise: true,
browser: true,
camelcase: true,
curly: true,
eqeqeq: true,
es3: true,
forin: true,
freeze: true,
funcscope: true,
globalstrict: true,
immed: true,
iterator: true,
latedef: true,
maxparams: 4,
newcap: true,
noarg: true,
nonbsp: true,
nonew: true,
notypeof: true,
quotmark: 'single',
shadow: true,
//singleGroups: true,
undef: true,
//unused: true, todo: add this back in when more stuff is working

failOnHint: true,
emitErrors: true
}
};

var exports = {};

exports.dev = extend(common, {
debug: true,
devtool: 'eval', //sourcemap?
output: {
path: './build/',
filename: 'vr.dev.js',
pathInfo: true
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
),
new webpack.DefinePlugin({
__DEV__: true,
__ASSET_PATH__: JSON.stringify('http://pov-tc.pbs.org/pov/flv/2015/webvr-starter-kit/')
})
],
});

exports.production = extend(common, {
devtool: 'source-map',
output: {
path: './build/',
filename: 'vr.js',
sourceMapFilename: '[file].map'
},
plugins: [
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
),
new webpack.DefinePlugin({
__DEV__: false,
__ASSET_PATH__: JSON.stringify('http://pov-tc.pbs.org/pov/flv/2015/webvr-starter-kit/')
}),
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
}),
new webpack.BannerPlugin(banner)
],
});

return exports;
}());
74 changes: 11 additions & 63 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ var gulp = require('gulp');
var gutil = require('gulp-util');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig = require('./webpack.config.js');
var combiner = require('stream-combiner2');
var config = require('./config');

// Build and watch cycle (another option for development)
// Advantage: No server required, can run app from filesystem
Expand All @@ -20,67 +19,21 @@ gulp.task('default', ['webpack:build-dev']);

// Production build
gulp.task('build', function(callback) {
// build two production versions - one minified, one not

var gulpWebpack = require('gulp-webpack');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
var pkg = require('./package.json');
var filter = require('gulp-filter');

var banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');

// modify some webpack config options
var productionConfig = Object.create(webpackConfig);
productionConfig.plugins.push(new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin()
);

var combined = combiner.obj([
gulp.src('src/entry.js'),
gulpWebpack(productionConfig),
header(banner, { pkg : pkg } ),
gulp.dest('build/'),
filter('**/*.js'),
rename(function (path) {
path.basename = path.basename.replace(/(\.dev)?$/, '');
}),
uglify(),
header(banner, { pkg : pkg } ),
gulp.dest('build/')
]);

combined.on('error', console.error.bind(console));

return combined;
var compiler = webpack(config.production);
compiler.run(function(err, stats) {
if(err) throw new gutil.PluginError('webpack:build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
callback();
});
});

// The development server (the recommended option for development)
gulp.task('server', ['webpack-dev-server']);

// modify some webpack config options
var myDevConfig = Object.create(webpackConfig);
myDevConfig.devtool = 'sourcemap';
myDevConfig.debug = true;
myDevConfig.output.pathInfo = true;
myDevConfig.plugins[1].definitions.__DEV__ = 'true';

// create a single instance of the compiler to allow caching
var devCompiler = webpack(myDevConfig);

var devCompiler = webpack(config.dev);
gulp.task('webpack:build-dev', function(callback) {
// run webpack
devCompiler.run(function(err, stats) {
Expand All @@ -96,13 +49,8 @@ gulp.task('webpack:build-dev', function(callback) {
This is broken right now. don't use it
*/
gulp.task('webpack-dev-server', function(callback) {
// modify some webpack config options
var myConfig = Object.create(webpackConfig);
myConfig.devtool = 'sourcemap';
myConfig.debug = true;

// Start a webpack-dev-server
new WebpackDevServer(webpack(myConfig), {
new WebpackDevServer(webpack(config.dev), {
publicPath: '/' + myConfig.output.publicPath,
stats: {
colors: true
Expand Down
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@
"event-emitter": "^0.3.2",
"file-loader": "^0.8.1",
"gulp": "^3.8.10",
"gulp-filter": "^2.0.2",
"gulp-header": "^1.2.2",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.2",
"gulp-webpack": "^1.1.2",
"imports-loader": "^0.6.3",
"jshint": "^2.6.0",
"jshint-loader": "^0.8.1",
"lodash.assign": "^3.0.0",
"lodash.foreach": "^3.0.1",
"main-bower-files": "^2.5.0",
"raw-loader": "^0.5.1",
"stream-combiner2": "^1.0.2",
"style-loader": "^0.12.0",
"three": "^0.71.0",
"url-loader": "^0.5.5",
"webpack": "^1.5.1",
"webpack-dev-server": "^1.7.0"
"webpack-dev-server": "^1.7.0",
"xtend": "^4.0.0"
}
}
85 changes: 0 additions & 85 deletions webpack.config.js

This file was deleted.

0 comments on commit 2d2151d

Please sign in to comment.