Skip to content

Instantly share code, notes, and snippets.

@stramel
Created May 11, 2018 06:14
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 stramel/bfcf2c8d2572f92a344bfc6247a51f08 to your computer and use it in GitHub Desktop.
Save stramel/bfcf2c8d2572f92a344bfc6247a51f08 to your computer and use it in GitHub Desktop.
Next.js v6 configs
{
"env": {
"development": {
"presets": ["next/babel"]
},
"production": {
"presets": ["next/babel"]
},
"test": {
"presets": [
[
"next/babel",
{
"preset-env": {
"modules": "commonjs"
}
}
]
]
}
},
"plugins": [
[
"module-resolver",
{
"root": ["./"],
"alias": {}
}
],
[
"styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}
const webpack = require('webpack')
const cfg = require('./config')
const { withPlugins, optional } = require('next-compose-plugins')
const withCSS = require('@zeit/next-css')
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer')
const withProgress = require('next-progressbar')
const nextConfig = {
webpack: (config, { dev, isServer }) => {
if (!isServer) {
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty',
}
}
config.plugins.push(new webpack.DefinePlugin({
'process.env.API_URL': JSON.stringify(cfg.api.url),
'process.env.API_REMOTE': JSON.stringify(cfg.api.remote),
'process.env.AUTH_URL': JSON.stringify(cfg.auth.url),
}))
config.plugins.push(new webpack.IgnorePlugin(/(?:\/tests|__mocks)/))
config.plugins.push(new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /(ru)/))
if (dev) {
config.output.crossOriginLoading = 'anonymous'
}
return config
},
distDir: 'dist',
}
module.exports = withPlugins(
[
[withCSS],
[
withBundleAnalyzer,
{
analyzeServer: ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
analyzeBrowser: ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
bundleAnalyzerConfig: {
server: {
analyzerPort: 8888,
},
browser: {
analyzerPort: 8000,
},
},
},
],
[withProgress],
],
nextConfig,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment