-
Notifications
You must be signed in to change notification settings - Fork 4
/
next.config.js
81 lines (72 loc) · 1.96 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
const path = require("path");
const fs = require("fs");
const requireHacker = require("require-hacker");
const glob = require("glob");
const { version } = require("./package.json");
function setupRequireHacker() {
const webjs = ".web.js";
const webModules = ["antd-mobile", "rmc-picker"].map(m =>
path.join("node_modules", m)
);
requireHacker.hook("js", filename => {
if (
filename.endsWith(webjs) ||
webModules.every(p => !filename.includes(p))
)
return;
const webFilename = filename.replace(/\.js$/, webjs);
if (!fs.existsSync(webFilename)) return;
return fs.readFileSync(webFilename, { encoding: "utf8" });
});
requireHacker.hook("svg", filename => {
return requireHacker.to_javascript_module_source(
`#${path.parse(filename).name}`
);
});
}
setupRequireHacker();
function moduleDir(m) {
return path.dirname(require.resolve(`${m}/package.json`));
}
module.exports = {
generateBuildId: async () => {
// For example get the latest git commit hash here
return `MY_BUILD_ID${version}`;
},
webpack: (config, { dev }) => {
config.resolve.extensions = [".web.js", ".js", ".json"];
config.module.rules.push(
{
test: /\.(svg)$/i,
loader: "emit-file-loader",
options: {
name: "dist/[path][name].[ext]"
},
include: [moduleDir("antd-mobile"), __dirname]
},
{
test: /\.(svg)$/i,
loader: "svg-sprite-loader",
include: [moduleDir("antd-mobile"), __dirname]
},
{
test: /\.(css|less)$/,
use: [
"babel-loader",
"raw-loader",
"postcss-loader",
{
loader: "less-loader",
options: {
includePaths: ["styles"]
.map(d => path.join(__dirname, d))
.map(g => glob.sync(g))
.reduce((a, c) => a.concat(c), [])
}
}
]
}
);
return config;
}
};