Skip to content

Instantly share code, notes, and snippets.

@moimikey
Created October 21, 2014 01:29
Show Gist options
  • Save moimikey/984bc4773561398b3401 to your computer and use it in GitHub Desktop.
Save moimikey/984bc4773561398b3401 to your computer and use it in GitHub Desktop.
ultimate webpack config. work in progress...
module.exports = {
port: 8000,
globals: {
$: 'jquery',
jQuery: 'jquery',
_: 'lodash',
Backbone: 'backbone',
Marionette: 'backbone.marionette',
moment: 'moment'
},
gzip: {
asset: '{file}.gz',
algorithm: 'gzip',
regExp: /\.js$/,
threshold: 10240,
minRatio: 0.8
},
source: {
root: 'src',
scripts: 'src/scripts',
styles: 'src/styles',
assets: 'src/assets',
fonts: 'src/assets/fonts',
images: 'src/assets/images',
sprites: 'src/assets/images/sprites'
},
destination: {
root: 'dist',
scripts: 'dist/scripts',
styles: 'dist/styles',
assets: 'dist/assets',
fonts: 'dist/assets/fonts',
images: 'dist/assets/images',
sprites: 'dist/assets/images/sprites'
},
loaders: [
{ test: /\.coffee$/, loader: 'coffee' },
{ test: /\.scss$/, loader: ['style', 'sass'], query: { includePaths: './bower_components' } },
{ test: /\.css$/, loader: ['style', 'css'] },
{ test: /\.json$/, loader: 'json' },
{ test: /\.png$/, loader: 'url', query: { limit: 8192, mimetype: 'image/png' } },
{ test: /\.jpg$/, loader: 'url', query: { limit: 8192, mimetype: 'image/jpg' } },
{ test: /\.gif$/, loader: 'url', query: { limit: 8192, mimetype: 'image/gif' } },
{ test: /\.woff$/, loader: 'url', query: { prefix: 'application/font-woff', limit: 5000, mimetype: 'application/font-woff' } },
{ test: /\.ttf$/, loader: 'file', query: { prefix: 'application/x-font-ttf' } },
{ test: /\.eot$/, loader: 'file', query: { prefix: 'application/octet-stream' } },
{ test: /\.svg$/, loader: 'file', query: { prefix: 'image/svg+xml' } }
]
};
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var webpack = require('webpack');
var config = require('./config');
var package = require('./package');
var compressionPlugin = require('compression-webpack-plugin');
var definePlugin = new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || true)),
__PROD__: JSON.stringify(JSON.parse(process.env.BUILD_PROD || false)),
__VERSION__: JSON.stringify(package['version']),
__SUPPORTS_HTML5__: JSON.stringify(true),
__GLOBALS__: JSON.stringify(Object.keys(config.globals)),
__CONFIG__: JSON.stringify(config)
});
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('Common', 'common.js');
var gzipPlugin = new compressionPlugin(config.gzip);
var globalsPlugin = new webpack.ProvidePlugin(config.globals);
var releasePlugin = function() {
"use strict";
this.apply(new webpack.optimize.DedupePlugin);
this.apply(new webpack.optimize.UglifyJsPlugin({
dropDebugger: true,
dropConsole: true
}));
this.apply(new webpack.optimize.OccurenceOrderPlugin);
this.apply(new webpack.optimize.AggressiveMergingPlugin);
};
var ignorePlugin = function() {
"use strict";
this.apply(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
};
module.exports = {
cache: !config.production,
debug: !config.production,
devtool: !config.production && 'eval',
watch: !config.production,
context: path.join(__dirname, 'app'),
entry: {
Index: './index.coffee',
Profile: './profile.coffee',
Feed: './feed.coffee'
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].[hash].js',
hotUpdateMainFilename: '[name].[hash].json',
hotUpdateChunkFilename: '[name].[hash]-hot.js',
jsonpFunction: 'xjsonp',
hotUpdateFunction: 'xhot'
},
module: {
noParse: /\.min\.js$/,
loaders: config.loaders,
preLoaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'jshint'
}],
postLoaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'coverjs'
}]
},
resolve: {
root: __dirname,
extensions: ['', '.coffee', '.js', '.json', '.scss'],
modulesDirectories: ['src', 'bower_components', 'node_modules', 'app/components'],
resolveLoader: {
root: __dirname
}
},
devServer: {
contentBase: './dist'
},
plugins: [definePlugin, gzipPlugin, globalsPlugin, ignorePlugin, commonsPlugin]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment