Skip to content

Commit 725f8c2

Browse files
ijjktimneutkens
authored andcommitted
Update ant design examples (vercel#7490)
* Update with-ant-design example to not need require.extensions hack * Update other ant-design examples to not use require.extensions hack
1 parent 79cf929 commit 725f8c2

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed

examples/with-ant-design-less/next.config.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,32 @@ const themeVariables = lessToJS(
99
fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8')
1010
)
1111

12-
// fix: prevents error when .less files are required by node
13-
if (typeof require !== 'undefined') {
14-
require.extensions['.less'] = file => {}
15-
}
16-
1712
module.exports = withLess({
1813
lessLoaderOptions: {
1914
javascriptEnabled: true,
2015
modifyVars: themeVariables, // make your antd custom effective
2116
},
17+
webpack: (config, { isServer }) => {
18+
if (isServer) {
19+
const antStyles = /antd\/.*?\/style.*?/
20+
const origExternals = [...config.externals]
21+
config.externals = [
22+
(context, request, callback) => {
23+
if (request.match(antStyles)) return callback()
24+
if (typeof origExternals[0] === 'function') {
25+
origExternals[0](context, request, callback)
26+
} else {
27+
callback()
28+
}
29+
},
30+
...(typeof origExternals[0] === 'function' ? [] : origExternals),
31+
]
32+
33+
config.module.rules.unshift({
34+
test: antStyles,
35+
use: 'null-loader',
36+
})
37+
}
38+
return config
39+
},
2240
})

examples/with-ant-design-less/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"less": "3.0.4",
1414
"less-vars-to-js": "1.3.0",
1515
"next": "latest",
16+
"null-loader": "2.0.0",
1617
"react": "^16.7.0",
1718
"react-dom": "^16.7.0"
1819
},
+24-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
/* eslint-disable */
22
const withCss = require('@zeit/next-css')
33

4-
// fix: prevents error when .css files are required by node
5-
if (typeof require !== 'undefined') {
6-
require.extensions['.css'] = file => {}
7-
}
4+
module.exports = withCss({
5+
webpack: (config, { isServer }) => {
6+
if (isServer) {
7+
const antStyles = /antd\/.*?\/style\/css.*?/
8+
const origExternals = [...config.externals]
9+
config.externals = [
10+
(context, request, callback) => {
11+
if (request.match(antStyles)) return callback()
12+
if (typeof origExternals[0] === 'function') {
13+
origExternals[0](context, request, callback)
14+
} else {
15+
callback()
16+
}
17+
},
18+
...(typeof origExternals[0] === 'function' ? [] : origExternals),
19+
]
820

9-
module.exports = withCss()
21+
config.module.rules.unshift({
22+
test: antStyles,
23+
use: 'null-loader',
24+
})
25+
}
26+
return config
27+
},
28+
})

examples/with-ant-design/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"antd": "^3.9.2",
1212
"babel-plugin-import": "^1.9.1",
1313
"next": "latest",
14+
"null-loader": "2.0.0",
1415
"react": "^16.7.0",
1516
"react-dom": "^16.7.0"
1617
},

examples/with-ant-design/pages/_document.js

-18
This file was deleted.
+24-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
const withCSS = require('@zeit/next-css')
22

3-
// fix: prevents error when .css files are required by node
4-
if (typeof require !== 'undefined') {
5-
// eslint-disable-next-line
6-
require.extensions['.css'] = file => {}
7-
}
3+
module.exports = withCSS({
4+
webpack: (config, { isServer }) => {
5+
if (isServer) {
6+
const antStyles = /antd-mobile\/.*?\/style.*?/
7+
const origExternals = [...config.externals]
8+
config.externals = [
9+
(context, request, callback) => {
10+
if (request.match(antStyles)) return callback()
11+
if (typeof origExternals[0] === 'function') {
12+
origExternals[0](context, request, callback)
13+
} else {
14+
callback()
15+
}
16+
},
17+
...(typeof origExternals[0] === 'function' ? [] : origExternals)
18+
]
819

9-
module.exports = withCSS()
20+
config.module.rules.unshift({
21+
test: antStyles,
22+
use: 'null-loader'
23+
})
24+
}
25+
return config
26+
}
27+
})

examples/with-antd-mobile/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"antd-mobile": "2.2.5",
77
"babel-plugin-import": "^1.2.1",
88
"next": "latest",
9+
"null-loader": "2.0.0",
910
"react": "^16.7.0",
1011
"react-dom": "^16.7.0"
1112
},

0 commit comments

Comments
 (0)