Skip to content

Instantly share code, notes, and snippets.

@eugene1g
Created March 5, 2015 03:49
Show Gist options
  • Save eugene1g/42289fecdab5a57a26e5 to your computer and use it in GitHub Desktop.
Save eugene1g/42289fecdab5a57a26e5 to your computer and use it in GitHub Desktop.
Our webpack setup
module.exports = require(".generate-config-template")({
hot: true,
devServer: true,
hotComponents: true,
devtool: "eval",
debug: true
});
/**
* Based on https://github.com/webpack/react-starter
*/
"use strict";
var path = require("path");
var webpack = require("webpack");
var fs = require("fs");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var APPDIR = path.join(__dirname, '..', '..', 'src', 'FA');
var DEPLOYDIR = path.join(__dirname, 'web/revved');
var sassIncluePath = APPDIR + '/WebBundle/Resources/css';
var jsResources = APPDIR + '/WebBundle/Resources/js';
var root = path.join(__dirname, "..", "..");
var entryPoints = {
billing: APPDIR + 'billing/',
userlist: APPDIR + 'userlist/',
reporting: APPDIR + 'reports/',
accounts: APPDIR + 'accounting/',
tutorial: APPDIR + 'tute/',
'platform-foundation': APPDIR + '/WebBundle/Resources/platform-foundation.js',
'lib-highcharts': [
'script!' + bowerDir + '/highcharts-release/adapters/standalone-framework',
'script!' + bowerDir + '/highcharts-release/highcharts',
'script!' + bowerDir + '/highcharts-release/highcharts-more',
'script!' + bowerDir + '/highcharts-release/modules/exporting',
'script!' + bowerDir + '/highcharts-release/modules/no-data-to-display',
'script!' + bowerDir + '/highcharts-release/modules/drilldown'
]
};
module.exports = function (options) {
var plugins = [];
if (options.hotComponents) {
//Automatically inject the hot-loader-client to all entry points
var devClient = ['webpack/hot/only-dev-server'];
Object.keys(entryPoints).forEach(function (key) {
entryPoints[key] = devClient.concat(entryPoints[key]);
});
}
var fileLoaders = [
{
test: /(web_modules|src).*\.jsx?$/,
exclude: /webpack/, //weback has an annoying web_modules folder of its own
loader: ( options.hotComponents ? "react-hot-loader!" : '') + "babel-loader?experimental"
},
{
test: /\.scss$/,
loader: options.separateStylesheet ?
ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader?includePaths[]=" + sassIncluePath)
: "style-loader!css-loader!sass-loader?includePaths[]=" + sassIncluePath
},
{
test: /\.css$/,
loader: options.separateStylesheet ?
ExtractTextPlugin.extract("style-loader", "css-loader")
: "style-loader!css-loader"
}
];
var publicPath = options.devServer ? "http://spring.dev:9020/_assets/" : "/revved/";
//var publicPath = options.devServer ? "http://172.16.24.1:9020/_assets/" : "/revved/";
var output = {
path: DEPLOYDIR,
publicPath: publicPath,
filename: "[name]-[chunkhash].js",
chunkFilename: (options.devServer ? "[id].js" : "[name].js") + (options.longTermCaching ? "?[chunkhash]" : ""),
//sourceMapFilename: "debugging/[file].map",
pathinfo: options.debug
};
plugins.push(
function () {
this.plugin("done", function (stats) {
var assetMapFilename = DEPLOYDIR + "/webpack-assetmap.json";
var webpackStats = stats.toJson({
chunkModules: true,
exclude: [
/node_modules[\\\/]react(-router)?[\\\/]/
]
});
var assetMapContent = {
assetsByChunkName: webpackStats.assetsByChunkName,
publicPath: publicPath
}
fs.writeFileSync(assetMapFilename, JSON.stringify(assetMapContent));
});
}
);
plugins.push(new webpack.optimize.CommonsChunkPlugin(
"platform-foundation",
"platform-foundation.js" + (options.longTermCaching && !options.prerender ? "-[chunkhash].js" : "")
));
if (options.separateStylesheet) {
plugins.push(new ExtractTextPlugin("[name]-[chunkhash].css"));
}
if (options.minimize) {
plugins.push(
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.UglifyJsPlugin({
//one sourcemap flag for webpack, anotherone for uglify itself
sourceMap: false,
compress: {
//drop_console: true,
//sourceMap: false,
warnings: false
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
//new webpack.NoErrorsPlugin()
);
} else {
plugins.push(new webpack.optimize.DedupePlugin());
}
return {
entry: entryPoints,
output: output,
module: {
loaders: fileLoaders
},
devtool: options.devtool,
debug: options.debug,
resolve: {
root: root,
//global module dir is required for webpack/hot/only-dev-server entry point
//production & dev
modulesDirectories: ["web_modules", "node_modules", "/usr/lib/node_modules", "/usr/local/lib/node_modules"],
extensions: ["", ".js", ".jsx"]
},
externals: {
jquery: 'jQuery'
},
resolveLoader: {
//production & dev
modulesDirectories: ["web_modules", "node_modules", "/usr/lib/node_modules", "/usr/local/lib/node_modules"]
},
plugins: plugins
};
};
front-server:
webpack-dev-server --config _dev/webpack/devserver.config.js --colors --port 9020 --hot
front-build:
webpack --config _dev/webpack/production-config.js
module.exports = require("./generate-config-template")({
longTermCaching: true,
separateStylesheet: true,
minimize: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment