Files
shields/next.config.js
T
Paul MelnikowandGitHub 102141123b Unify lint rules and clean lint (#2009)
Now that server.js is emptied out, it makes sense to eliminate the differences between the top-level .js files and everything else.
2018-09-01 11:08:17 -07:00

44 lines
1.2 KiB
JavaScript

'use strict'
const envFlag = require('node-env-flag');
const webpack = require('webpack');
const shouldAnalyze = envFlag(process.env.ANALYZE);
const assetPrefix = process.env.NEXT_ASSET_PREFIX;
module.exports = {
webpack: config => {
config.plugins.push(new webpack.EnvironmentPlugin({ BASE_URL: null, LONG_CACHE: null }));
if (shouldAnalyze) {
// We don't include webpack-bundle-analyzer in devDependencies, so load
// lazily.
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: 8888,
openAnalyzer: true,
}));
}
config.module.loaders = (config.module.loaders || []).concat({
test: /\.json$/,
loader: 'json-loader',
});
if (assetPrefix) {
config.output.publicPath = `${assetPrefix}/${config.output.publicPath}`;
}
return config;
},
exportPathMap: () => ({
'/': { page: '/' },
}),
};
// Avoid setting an `undefined` value. This causes
// `TypeError: Cannot read property 'replace' of undefined` at build time.
if (assetPrefix) {
module.exports.assetPrefix = assetPrefix;
}