-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
50 lines (46 loc) · 1.28 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
const webpack = require('webpack');
const path = require('path');
const siteNodeModules = path.join(__dirname, 'node_modules');
const componentsPath = path.join(path.dirname(__dirname), 'components');
const componentsNodePath = path.join(
path.dirname(__dirname),
'components',
'node_modules',
);
function isInternalPath(filename) {
return filename.startsWith(componentsPath) && !filename.startsWith(componentsNodePath);
}
function isInternalReq(req) {
const parts = req.split('!');
const resource = parts[parts.length - 1];
return resource.startsWith('components/');
}
module.exports = {
webpack: (config, {dev, isServer, defaultLoaders}) => {
config.externals = config.externals.map(external => {
if (typeof external !== 'function') {
return external;
}
return (ctx, req, cb) => {
if (isInternalReq(req)) {
return cb();
} else {
return external(ctx, req, cb);
}
};
});
config.resolve.modules = [siteNodeModules, 'node_modules'];
config.module.rules.push({
test: /\.+(js|jsx)$/,
loader: defaultLoaders.babel,
include(path) {
if (isInternalPath(path)) {
return true;
} else {
return false;
}
},
});
return config;
},
};