Created
June 28, 2016 05:26
-
-
Save AndrewRayCode/c28fc19655567d71a8f81861dc75628d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Webpack config for development | |
var fs = require('fs'); | |
var path = require('path'); | |
var webpack = require('webpack'); | |
var assetsPath = path.resolve(__dirname, '../static/dist'); | |
var host = (process.env.HOST || 'localhost'); | |
var port = parseInt(process.env.PORT) + 1 || 3001; | |
// https://github.com/halt-hammerzeit/webpack-isomorphic-tools | |
var WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin'); | |
var webpackIsomorphicToolsPlugin = new WebpackIsomorphicToolsPlugin(require('./webpack-isomorphic-tools')); | |
var WebpackNotifierPlugin = require('webpack-notifier'); | |
var babelrc = fs.readFileSync('./.babelrc'); | |
var babelrcObject = {}; | |
try { | |
babelrcObject = JSON.parse(babelrc); | |
} catch (err) { | |
console.error('==> ERROR: Error parsing your .babelrc.'); | |
console.error(err); | |
} | |
var babelrcObjectDevelopment = babelrcObject.env && babelrcObject.env.development || {}; | |
// merge global and dev-only plugins | |
var combinedPlugins = babelrcObject.plugins || []; | |
combinedPlugins = combinedPlugins.concat(babelrcObjectDevelopment.plugins); | |
var babelLoaderQuery = Object.assign({}, babelrcObjectDevelopment, babelrcObject, {plugins: combinedPlugins}); | |
delete babelLoaderQuery.env; | |
// Since we use .babelrc for client and server, and we don't want HMR enabled on the server, we have to add | |
// the babel plugin react-transform-hmr manually here. | |
// make sure react-transform is enabled | |
babelLoaderQuery.plugins = babelLoaderQuery.plugins || []; | |
var reactTransform = null; | |
for (var i = 0; i < babelLoaderQuery.plugins.length; ++i) { | |
var plugin = babelLoaderQuery.plugins[i]; | |
if (Array.isArray(plugin) && plugin[0] === 'react-transform') { | |
reactTransform = plugin; | |
} | |
} | |
if (!reactTransform) { | |
reactTransform = ['react-transform', {transforms: []}]; | |
babelLoaderQuery.plugins.push(reactTransform); | |
} | |
if (!reactTransform[1] || !reactTransform[1].transforms) { | |
reactTransform[1] = Object.assign({}, reactTransform[1], {transforms: []}); | |
} | |
// make sure react-transform-hmr is enabled | |
reactTransform[1].transforms.push({ | |
transform: 'react-transform-hmr', | |
imports: ['react'], | |
locals: ['module'] | |
}); | |
module.exports = { | |
devtool: 'inline-source-map', // cheap-module-source-map ? | |
context: path.resolve(__dirname, '..'), | |
progress: true, | |
entry: { | |
main: [ | |
'webpack-hot-middleware/client?path=http://' + host + ':' + port + '/__webpack_hmr', | |
'font-awesome-webpack!./src/theme/font-awesome.config.js', | |
'./src/client.js' | |
], | |
}, | |
output: { | |
path: assetsPath, | |
filename: 'app.js', | |
publicPath: 'http://' + host + ':' + port + '/dist/' | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.typeface\.js$/, loader: "file" }, | |
{ test: /\.jsx?$/, exclude: /node_modules|\.typeface\.js$/, loaders: ['babel?' + JSON.stringify(babelLoaderQuery)]}, | |
{ test: /models.+\.json$/, loader: "file" }, | |
{ test: /\.json$/, exclude: /models.+\.json$/, loader: "json-loader" }, | |
{ test: /\.less$/, loader: "style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!less?outputStyle=expanded&sourceMap" }, | |
{ test: /\.scss$/, exclude: /global\.scss$/, loader: "style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap" }, | |
// Note the global laoder does not have localIdentName nor modules enabled | |
// for the css loader, so any classes in there won't get mangled | |
{ test: /global\.scss$/, loader: "style!css?importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap" }, | |
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" }, | |
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" }, | |
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" }, | |
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" }, | |
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }, | |
{ test: /\.(obj|dae)$/, loader: "file" }, | |
{ test: webpackIsomorphicToolsPlugin.regular_expression('images'), loader: 'url-loader?limit=10240' } | |
] | |
}, | |
resolve: { | |
modulesDirectories: [ | |
'src', | |
'assets', | |
'node_modules' | |
], | |
extensions: [ '', '.json', '.js', '.jsx' ] | |
}, | |
plugins: [ | |
new webpack.DllReferencePlugin({ | |
context: path.join( __dirname, '../' ), | |
manifest: require(path.join(assetsPath, 'vendor-manifest.json')), | |
}), | |
new webpack.DllReferencePlugin({ | |
context: path.join( __dirname, '../' ), | |
manifest: require(path.join(assetsPath, 'assets-manifest.json')), | |
}), | |
// hot reload | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NoErrorsPlugin(), | |
new webpack.IgnorePlugin(/webpack-stats\.json$/), | |
new webpack.DefinePlugin({ | |
// Including the below code gets an extra 10fps, and removes "resource | |
// was not in this map?" error on hot reloading some functions | |
'process.env': { | |
NODE_ENV: '"production"' | |
}, | |
__CLIENT__: true, | |
__SERVER__: false, | |
__DEVELOPMENT__: true, | |
__DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE | |
}), | |
//webpackIsomorphicToolsPlugin.development(), | |
//new webpack.optimize.CommonsChunkPlugin( 'common.js' ), | |
new WebpackNotifierPlugin(), | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment