forked from OperationCode/front-end
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
105 lines (92 loc) · 2.71 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const withCSS = require('@innocuous/next-css');
const withSourceMaps = require('@zeit/next-source-maps')();
const withBundleAnalyzer = require('@zeit/next-bundle-analyzer');
const svgoConfig = require('./common/config/svgo');
const nextConfig = withCSS({
// For now.sh
// see: https://zeit.co/guides/deploying-nextjs-with-now/
target: 'serverless',
// NextCSS Config
cssModules: true,
cssLoaderOptions: {
modules: {
localIdentName: '[name]_[local]__[hash:base64:5]',
},
},
// Bundle Analyzer Config (only used when running `yarn build:analyze`)
analyzeServer: process.env.ANALYZE,
analyzeBrowser: process.env.ANALYZE,
bundleAnalyzerConfig: {
server: {
analyzerMode: 'server',
analyzerPort: 8888,
},
browser: {
analyzerMode: 'server',
analyzerPort: 8889,
},
},
// eslint-disable-next-line unicorn/prevent-abbreviations
webpack: (config, { dev }) => {
// Fixes npm packages that depend on `fs` module
// eslint-disable-next-line no-param-reassign
config.node = { fs: 'empty' };
if (dev) {
// eslint-disable-next-line global-require
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
// Filters Mini CSS Extract Plugin bug
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/250#issuecomment-415345126
config.plugins.push(
new FilterWarningsPlugin({
exclude: /mini-css-extract-plugin[^]*Conflicting order between:/,
}),
);
}
config.module.rules.push(
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
svgoConfig,
},
},
],
},
{
test: /\.(jpe?g|png|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
fallback: {
loader: 'file-loader',
options: {
publicPath: '/_next/static/images',
outputPath: 'static/images',
},
},
publicPath: '/_next/',
outputPath: 'static/images/',
name: '[name]-[hash].[ext]',
},
},
],
},
);
// Add polyfills
const originalEntry = config.entry;
// eslint-disable-next-line no-param-reassign
config.entry = async () => {
const entries = await originalEntry();
if (entries['main.js'] && !entries['main.js'].includes('./polyfills.js')) {
entries['main.js'].unshift('./polyfills.js');
}
return entries;
};
return config;
},
});
module.exports = withSourceMaps(withBundleAnalyzer(nextConfig));