Files
shields/next.config.js
Paul Melnikow e39b280d44 Fixes for github deploy (#1774)
This addresses some long-standing comments in https://github.com/badges/shields/issues/1458#issuecomment-368270996

We should also adopt Gatsby, create-react-app, or something similar designed for static sites, to eliminate the unnecessary runtime dependency on Next.js while also letting someone else maintain our front-end tooling. :-D These alternative tools might work just fine in subdirectories without config, and we might be able to leave Jekyll turned on (though we don’t need it). However these git-related changes are orthogonal.

- Don’t check out master, making it possible to deploy the currently checked-out commit
- Disable Jekyll which we don’t need. This allows _next folders to be deployed, and the related URL rewriting to be removed.
- Completely empty the deploy branch’s index before deployment. This prevents errors from broken symlinks, while preserving the commit history in the deploy branch.
- Do the deployment work in a git working tree. This requires Git 2.18 but makes it possible to do the above very safely.
2018-07-18 19:46:27 -07:00

42 lines
1.2 KiB
JavaScript

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;
}