-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
65 lines (60 loc) · 2.94 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
/*************************************************************************
* Copyright (c) 2019 - 2019 Yichao Yu <[email protected]> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 3.0 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. If not, *
* see <http://www.gnu.org/licenses/>. *
*************************************************************************/
"use strict";
const path = require('path');
const root = path.resolve(__dirname);
const blacklist_prefix = [
// These module are server only and shouldn't be compiled.
// They may even contains dynamic loading code and can't be compiled.
// See `lib/api.js` for the API caller.
path.join(root, 'server/'),
path.join(root, 'apis/')
];
module.exports = {
distDir: (process.env.NEXT_DIST_DIR ? process.env.NEXT_DIST_DIR : '.next'),
generateBuildId: async () => {
if (process.env.NEXT_BUILD_ID)
return process.env.NEXT_BUILD_ID
return null
},
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
if (config.externals === undefined)
config.externals = [];
if (!Array.isArray(config.externals))
config.externals = [config.externals];
// Blacklist modules that we don't want to be packaged
config.externals.push(function ({context, request}, callback) {
if (request[0] == '.') {
let p = path.join(context, request);
for (let i in blacklist_prefix) {
let prefix = blacklist_prefix[i];
if (p.startsWith(prefix)) {
// Load the module normally on the server
// and load `null` on the client.
return callback(null, isServer ? p : "null");
}
}
}
return callback();
});
return config
},
};