ducky/web

Paddy 2015-05-31 Parent:b9d0efb44eaa Child:5d47855181e1

6:a641906b8267 Go to Latest

ducky/web/webpack.config.js

Enable catch-all in our ValidationError component. We're doing this an ugly, hacky way. But it works, and right now, that's what counts. To match our params/fields/headers properties on the ValidationError component, we're going to add the notParams/notFields/notHeaders properties--they match any error _not_ targeting those params/fields/headers. Basically, "any error that wouldn't be caught by these filters". Which is an ugly, but workable, solution for a catch-all ValidationError--just tell it to catch anything but the params/fields/headers that are being handled by the other ValidationErrors. Our implementation of this in the RegisterPage component validates (ha!) that it's at least workable model, if not overly pretty. Also, I anticipate some human error bugs in the future, where one of the field-specific ValidationErrors gets updated and the catch-all ValidationError does not. But whatever. For now, this is Good Enoughâ„¢.

History
paddy@0 1 require('babel/register')
paddy@0 2 var webpack = require('webpack')
paddy@0 3 var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js')
paddy@0 4 var ExtractTextPlugin = require('extract-text-webpack-plugin')
paddy@0 5 var path = require('path')
paddy@0 6 var neat = require('node-neat').includePaths
paddy@0 7 var env = process.env.NODE_ENV || 'development'
paddy@0 8
paddy@0 9 module.exports = function () {
paddy@0 10 var isDev = env !== 'production'
paddy@0 11 var cssLoader = isDev ? 'css-loader?sourceMap' : 'css-loader'
paddy@0 12 var sassLoader = isDev ? 'sass-loader?sourceMap' : 'sass-loader'
paddy@0 13 var bourbonPaths = neat.map(function(p) {
paddy@0 14 return "includePaths[]=" + p
paddy@0 15 }).join("&")
paddy@0 16 if (sassLoader.indexOf('?') === -1) {
paddy@0 17 sassLoader += '?'
paddy@0 18 } else {
paddy@0 19 sassLoader += '&'
paddy@0 20 }
paddy@0 21 sassLoader += bourbonPaths
paddy@0 22 var manifest = {
paddy@0 23 entry: path.join(__dirname, 'src', 'main.js'),
paddy@0 24 output: {
paddy@2 25 path: path.join(__dirname, 'build', 'static'),
paddy@0 26 publicPath: '/static/',
paddy@0 27 filename: 'bundle.js'
paddy@0 28 },
paddy@0 29 module: {
paddy@0 30 loaders: [
paddy@0 31 { test: /(\.js$)|(\.jsx$)/, loader: 'babel-loader', exclude: /node_modules/ },
paddy@0 32 { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', cssLoader) },
paddy@0 33 { test: /\.scss$/, loader: ExtractTextPlugin.extract('style-loader', cssLoader + '!' + sassLoader) },
paddy@0 34 { test: /\.(svg|png|jpg|jpeg)$/, loader: 'url-loader?limit=8192'}
paddy@0 35 ]
paddy@0 36 },
paddy@0 37 resolve: {
paddy@0 38 extensions: ['', '.js', '.jsx', '.scss']
paddy@0 39 },
paddy@0 40 plugins: [commonsPlugin, new ExtractTextPlugin("main.css")],
paddy@0 41 modulesDirectoires: ["node_modules"],
paddy@0 42 }
paddy@0 43 if (isDev) {
paddy@0 44 manifest.host = '0.0.0.0'
paddy@0 45 manifest.port = '3000'
paddy@0 46 manifest.devtool = 'source-map'
paddy@0 47
paddy@0 48 if (typeof manifest.entry === 'string') {
paddy@0 49 manifest.entry = [manifest.entry]
paddy@0 50 }
paddy@0 51
paddy@0 52 manifest.entry.unshift(
paddy@0 53 'webpack-dev-server/client?http://' + manifest.host + ':' + manifest.port,
paddy@0 54 'webpack/hot/dev-server'
paddy@0 55 )
paddy@0 56
paddy@0 57 manifest.plugins = manifest.plugins.concat([
paddy@0 58 new webpack.HotModuleReplacementPlugin(),
paddy@0 59 new webpack.NoErrorsPlugin()
paddy@0 60 ])
paddy@0 61
paddy@0 62 if (manifest.module.loaders[0].loader && !manifest.module.loaders[0].loaders) {
paddy@0 63 manifest.module.loaders[0].loaders = [manifest.module.loaders[0].loader]
paddy@0 64 delete manifest.module.loaders[0].loader
paddy@0 65 }
paddy@0 66
paddy@0 67 manifest.module.loaders[0].loaders.unshift('react-hot')
paddy@0 68 } else {
paddy@0 69 manifest.plugins.push(
paddy@0 70 new webpack.optimize.DedupePlugin(),
paddy@0 71 new webpack.optimize.OccurenceOrderPlugin(true),
paddy@0 72 new webpack.optimize.UglifyJsPlugin({
paddy@0 73 compress: {
paddy@0 74 warnings: false
paddy@0 75 },
paddy@0 76 output: {
paddy@0 77 comments: false
paddy@0 78 },
paddy@0 79 sourceMap: false
paddy@0 80 }),
paddy@0 81 new webpack.DefinePlugin({
paddy@0 82 'process.env': {NODE_ENV: JSON.stringify('production')}
paddy@0 83 })
paddy@0 84 )
paddy@0 85 }
paddy@0 86 return manifest
paddy@0 87 }()