Skip to content

Instantly share code, notes, and snippets.

@ezekielchentnik
Last active May 19, 2016 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezekielchentnik/2da9dcb647949126fe8159d5c8dc2d54 to your computer and use it in GitHub Desktop.
Save ezekielchentnik/2da9dcb647949126fe8159d5c8dc2d54 to your computer and use it in GitHub Desktop.
require('babel-register');
module.exports = require('./webpack.client');
module.exports = (process.env.BABEL_ENV && process.env.BABEL_ENV === 'development') ? true: false;
function StatusWebpackPlugin(options) {}
StatusWebpackPlugin.prototype.apply = function(compiler) {
compiler.plugin("compile", function() {
setTimeout(function(){
console.log("webpack is compiling, dude...");
},0);
});
compiler.plugin("emit", function(compilation, callback) {
console.log("webpack is going to emit files...");
callback();
});
compiler.plugin("done", function() {
setTimeout(function(){
console.log("webpack say it good, fire up...\n");
},0);
});
}
export default StatusWebpackPlugin;
{
"compress": {
"warnings": false,
"screw_ie8": true,
"sequences": true,
"dead_code": true,
"drop_debugger": true,
"comparisons": true,
"conditionals": true,
"evaluate": true,
"booleans": true,
"loops": true,
"unused": true,
"hoist_funs": true,
"if_return": true,
"join_vars": true,
"cascade": true,
"drop_console": true
},
"output": {
"comments": false
}
}
import IS_DEV from '../src/server/utils/isDev';
import path from 'path';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CleanWebpackPlugin from 'clean-webpack-plugin';
import AssetsPlugin from 'assets-webpack-plugin';
import WebpackSHAHash from 'webpack-sha-hash';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import StatusPlugin from './status-webpack-plugin';
const hash = IS_DEV ? '[name]' : '[name]-[chunkhash]';
const root = process.cwd();
const styleLoaders = ['css?minimize&sourceMap&importLoaders=5', 'postcss', 'sass?sourceMap'];
const prefetches = ['react', 'redux', 'd3', 'moment', 'classnames'];
var plugins = [
new webpack.SourceMapDevToolPlugin('[file].map', "\n//# sourceMappingURL=/summary/static/[url]"),
new AssetsPlugin({ filename: 'asset-manifest.json', path: path.join(root, '/build/static') }),
new CaseSensitivePathsPlugin(),
new CleanWebpackPlugin([path.join(root, '/build/static')], {'verbose': false}),
new webpack.optimize.CommonsChunkPlugin('vendor', hash + '.js', (module) => {
return module.resource && module.resource.indexOf(path.join(root, 'node_modules')) === 0;
}),
new webpack.optimize.CommonsChunkPlugin({ names: ["vendor", "manifest"] }),
new webpack.DefinePlugin({
'IS_BROWSER': true,
'IS_DEV': IS_DEV,
'process.env.NODE_ENV': JSON.stringify(IS_DEV ? 'development' : 'production')
}),
...prefetches.map((i) => new webpack.PrefetchPlugin(i)),
...(IS_DEV ? [
new webpack.HotModuleReplacementPlugin(),
new StatusPlugin()
] : [
new webpack.optimize.MinChunkSizePlugin({ minChunkSize: 40000 }),
new webpack.ContextReplacementPlugin(/.*$/, /NEVER_MATCH^/), // ignore dynamic reqires
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new WebpackSHAHash(),
new webpack.optimize.AggressiveMergingPlugin(),
new ExtractTextPlugin(hash + '.css'),
new webpack.optimize.UglifyJsPlugin(require('./uglifyjs.json'))
]
)
];
module.exports = {
context: path.join(root, 'src'),
entry: {
main: IS_DEV ? ['./client/js/index.js', 'webpack-hot-middleware/client', './client/scss/index.scss'] : ['./client/js/index.js', './client/scss/index.scss'],
prerender: ['./client/scss/prerender.scss'],
serviceworker: ['./client/js/utils/serviceworker.js']
},
output: {
path: path.join(root, '/build/static'),
publicPath: IS_DEV ? `http://localhost:8080/summary/static/` : '/summary/static/', // needed so fonts can be found
filename: hash + '.js',
chunkFilename: hash + '.js'
},
plugins: plugins,
module: {
loaders: [{
test: /\.js$/,
loader: 'babel',
include: path.join(root, 'src'),
query: {
cacheDirectory: IS_DEV,
babelrc: false,
presets: [
'react',
'es2015',
...(IS_DEV) ? ['react-hmre'] : []
],
plugins: [
'transform-object-assign',
'transform-object-rest-spread',
...(IS_DEV) ? [] : [
'transform-react-remove-prop-types',
'transform-react-constant-elements',
'transform-react-inline-elements',
]
]
},
},
{
test: /\.json$/, loader: 'json'
},
{
test: /\.(jpe?g|png|gif)([\?]?.*)$/,
include: [path.join(root, 'src/client')],
loaders: [
'url?limit=100&digest=hex',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
},
{
test: /\.(woff|woff2|eot|ttf|svg)([\?]?.*)$/,
loader: 'file?name=[name].[ext]' //name fonts to enable dedupe shared header/footer fonts
},
{
test: /.s?css$/,
include: [path.join(root, 'src/client'), path.resolve(root, 'node_modules')],
loader: IS_DEV ? 'style!' + styleLoaders.join('!') : ExtractTextPlugin.extract('style', styleLoaders)
}
]
},
postcss: function () {
return [
require('autoprefixer')({ browsers: ['last 2 versions'] })
];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment