freeCodeCamp/webpack.config.js

83 lines
2.1 KiB
JavaScript
Raw Normal View History

const webpack = require('webpack');
const path = require('path');
const ManifestPlugin = require('webpack-manifest-plugin');
const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
const Visualizer = require('webpack-visualizer-plugin');
2018-07-31 12:18:03 +00:00
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
2015-11-23 04:26:44 +00:00
var __DEV__ = process.env.NODE_ENV !== 'production';
2015-06-29 16:50:25 +00:00
module.exports = {
entry: {
2018-07-31 15:33:56 +00:00
client: './client/index.js',
news: './news/index.js'
},
devtool: __DEV__ ? 'inline-source-map' : 'source-map',
2018-07-31 09:47:31 +00:00
mode: __DEV__ ? 'development' : 'production',
node: {
// Mock Node.js modules that Babel require()s but that we don't
// particularly care about.
fs: 'empty',
module: 'empty',
net: 'empty'
},
2015-06-29 16:50:25 +00:00
output: {
2018-07-31 15:33:56 +00:00
filename: __DEV__ ? '[name]-app.js' : '[name]-app-[hash].js',
chunkFilename: __DEV__ ?
2018-07-31 15:33:56 +00:00
'[name]-chunk.js' :
'[name]-chunk-[chunkhash].js',
path: path.join(__dirname, '/public/js/'),
publicPath: '/js'
2018-01-09 04:09:54 +00:00
},
2015-06-29 16:50:25 +00:00
module: {
2018-01-09 04:09:54 +00:00
rules: [{
test: /\.jsx?$/,
2018-07-31 15:33:56 +00:00
exclude: /node_modules/,
2018-01-09 04:09:54 +00:00
use: [
__DEV__ && 'react-hot-loader',
'babel-loader'
].filter(Boolean)
}]
2015-06-29 16:50:25 +00:00
},
2015-11-23 04:26:44 +00:00
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(__DEV__ ? 'development' : 'production')
2015-11-23 04:26:44 +00:00
},
__DEVTOOLS__: !__DEV__
}),
2017-01-08 21:44:30 +00:00
// Use browser version of visionmedia-debug
new webpack.NormalModuleReplacementPlugin(
/debug\/node/,
'debug/src/browser'
2018-01-09 04:09:54 +00:00
)
2018-07-31 12:18:03 +00:00
],
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.js($|\?)/i,
cache: true,
sourceMap: true,
parallel: true
})
]
}
2015-06-29 16:50:25 +00:00
};
if (!__DEV__) {
module.exports.plugins.push(
new ManifestPlugin({ fileName: 'react-manifest.json' }),
new ChunkManifestPlugin({
filename: 'chunk-manifest.json',
manifestVariable: 'webpackManifest'
})
);
} else {
module.exports.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
2018-01-09 04:09:54 +00:00
// this will output a .html file in output.path
new Visualizer({ filename: 'webpack-bundle-stats.html' })
);
}