-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.js
More file actions
94 lines (84 loc) · 2.37 KB
/
Copy pathnext.config.js
File metadata and controls
94 lines (84 loc) · 2.37 KB
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
/* eslint-disable import/no-extraneous-dependencies */
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
// const withPWA = require('next-pwa');
// const runtimeCaching = require('next-pwa/cache');
const withPlugins = require('next-compose-plugins');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
// const isProd = process.env.NODE_ENV === 'production';
// ESBUILD LOADER
function useEsbuildMinify(config, options) {
const terserIndex = config.optimization.minimizer.findIndex(
minimizer => minimizer.constructor.name === 'TerserPlugin'
);
if (terserIndex > -1) {
config.optimization.minimizer.splice(
terserIndex,
1,
new ESBuildMinifyPlugin(options)
);
}
}
function useEsbuildLoader(config, options) {
const tsxLoader = config.module.rules.find(
rule => rule.test && rule.test.test(/\.tsx?$/)
);
if (tsxLoader) {
tsxLoader.use.loader = 'esbuild-loader';
tsxLoader.use.options = options;
}
}
module.exports = withPlugins(
[withBundleAnalyzer], // All next plugins go here
// Below is the main Next.js config object
{
poweredByHeader: false,
trailingSlash: true,
basePath: '',
reactStrictMode: true,
pageExtensions: ['js', 'jsx', 'md', 'tsx', 'mdx'],
eslint: {
dirs: ['src', 'e2e', 'docs'],
},
webpack: (config, { dev, isServer }) => {
config.module.rules.push({
test: /\.(png|jpe?g|gif|mp4)$/i,
use: [
{
loader: 'file-loader',
options: {
publicPath: '/_next',
name: 'static/media/[name].[hash].[ext]',
},
},
],
});
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
useEsbuildMinify(config);
useEsbuildLoader(config, {
loader: 'tsx',
target: 'es2017',
});
if (!dev && !isServer) {
// Replace React with Preact only in client production build
Object.assign(config.resolve.alias, {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
});
}
return config;
},
// pwa: {
// dest: 'public',
// register: true,
// skipWaiting: true,
// runtimeCaching,
// disable: !isProd,
// },
}
);