-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnext.config.js
85 lines (74 loc) · 2.32 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
const path = require('path')
const withCSS = require('@zeit/next-css')
const withSass = require('@zeit/next-sass')
const withLess = require('@zeit/next-less')
const reScript = /\.(js|jsx|mjs)$/
const nextConfig = {
webpack: config => {
const isDev = config.mode === 'development'
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty'
}
// https://github.com/zeit/Pang.js/blob/master/packages/next/build/webpack-config.ts
if (!isDev) {
const moduleToBeResolved = /node_modules[\\\/](bizcharts|react-intl|intl-messageformat|intl-messageformat-parser|query-string|split-on-first|engine.io-client|strict-uri-encode)[\\\/]/
config.module.rules[0].include.push(/(browser|common)\.js/, moduleToBeResolved)
config.module.rules[0].exclude = path => {
if (
/next[\\/]dist[\\/]next-server[\\/]lib/.test(path) ||
/next[\\/]dist[\\/]client/.test(path) ||
/next[\\/]dist[\\/]pages/.test(path) ||
/[\\/](strip-ansi|ansi-regex)[\\/]/.test(path) ||
/(browser|common)\.js/.test(path)
) {
return false
}
if (/node_modules/.test(path)) {
return !moduleToBeResolved.test(path)
}
}
}
const originalEntry = config.entry
config.entry = async () => {
const entries = await originalEntry()
if (entries['main.js'] && !entries['main.js'].includes('./lib/polyfills.js')) {
entries['main.js'].unshift('./lib/polyfills.js')
}
return entries
}
config.module.rules.push(
{
test: /\.md$/,
loader: path.resolve(__dirname, './lib/markdown-loader.js')
},
{
test: /\.(yaml|yml)$/,
use: ['json-loader', 'yaml-loader']
}
)
if (isDev) {
config.module.rules.push({
test: reScript,
loader: 'eslint-loader',
exclude: ['/node_modules/', '/.next/', '/out/'],
enforce: 'pre',
options: {
emitWarning: true
}
})
}
return config
},
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: {
hack: `true; @import "../../../antd-theme.less";`
}
},
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: 'secret'
}
}
module.exports = withSass(withCSS(withLess(nextConfig)))