-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
103 lines (91 loc) · 2.63 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
/* eslint-disable global-require */
const { IgnorePlugin } = require('webpack');
const OfflinePlugin = require('offline-plugin');
const router = require('./routes');
const Dotenv = require('dotenv-webpack');
const initExport = {
webpack: (config, { dev }) => {
const prod = !dev;
config.plugins.push(new Dotenv({ path: './public.env' }));
config.plugins.push(new IgnorePlugin(/^\.\/locale$/, /moment$/));
if (dev) {
config.module.rules.push({
test: /\.(jsx?|gql|graphql)$/,
loader: 'eslint-loader',
exclude: ['/node_modules/', '/.next/', '/helper_scripts/'],
enforce: 'pre'
});
}
if (process.env.ANALYZE_BUILD) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: 8888,
openAnalyzer: true
})
);
}
if (prod && process.env.OFFLINE_SUPPORT) {
config.plugins.push(
new OfflinePlugin({
publicPath: '/',
relativePaths: false,
externals: ['/', '/manifest.html'],
excludes: ['.htaccess'],
safeToUseOptionalCaches: true,
caches: 'all',
rewrites: function rewrites(asset) {
if (
asset.indexOf('.hot-update.js') > -1 ||
asset.indexOf('build-stats.json') > -1 ||
asset === 'BUILD_ID' ||
asset.indexOf('dist/') === 0
) {
return null;
}
if (asset[0] === '/') {
return asset;
}
if (asset.indexOf('bundles/pages/') === 0) {
return `/_next/-/${asset
.replace('bundles/pages', 'page')
.replace('index.js', '')
.replace(/\.js$/, '')}`;
}
return `/_next/-/${asset}`;
},
autoUpdate: 1000 * 60 * 5,
__tests: dev ? { ignoreRuntime: true } : {},
ServiceWorker: {
events: true,
navigateFallbackURL: '/'
},
AppCache: {
directory: './',
events: true
}
})
);
}
return config;
}
};
if (process.env.STATIC_EXPORT) {
initExport.exportPathMap = function exportPathMap() {
const routes = {};
routes['/'] = {
page: 'index'
};
router.routes.forEach(route => {
if (!route.pattern.includes(':')) {
routes[route.pattern] = {
page: route.page
};
}
});
return routes;
};
}
/* eslint-enable global-require */
module.exports = initExport;