Commit 725f8c2b authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

Update ant design examples (#7490)

* Update with-ant-design example to not
need require.extensions hack

* Update other ant-design examples to not
use require.extensions hack
parent 79cf929b
...@@ -9,14 +9,32 @@ const themeVariables = lessToJS( ...@@ -9,14 +9,32 @@ const themeVariables = lessToJS(
fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8') fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8')
) )
// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
require.extensions['.less'] = file => {}
}
module.exports = withLess({ module.exports = withLess({
lessLoaderOptions: { lessLoaderOptions: {
javascriptEnabled: true, javascriptEnabled: true,
modifyVars: themeVariables, // make your antd custom effective modifyVars: themeVariables, // make your antd custom effective
}, },
webpack: (config, { isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style.*?/
const origExternals = [...config.externals]
config.externals = [
(context, request, callback) => {
if (request.match(antStyles)) return callback()
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback)
} else {
callback()
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
]
config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
})
}
return config
},
}) })
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"less": "3.0.4", "less": "3.0.4",
"less-vars-to-js": "1.3.0", "less-vars-to-js": "1.3.0",
"next": "latest", "next": "latest",
"null-loader": "2.0.0",
"react": "^16.7.0", "react": "^16.7.0",
"react-dom": "^16.7.0" "react-dom": "^16.7.0"
}, },
......
/* eslint-disable */ /* eslint-disable */
const withCss = require('@zeit/next-css') const withCss = require('@zeit/next-css')
// fix: prevents error when .css files are required by node module.exports = withCss({
if (typeof require !== 'undefined') { webpack: (config, { isServer }) => {
require.extensions['.css'] = file => {} if (isServer) {
} const antStyles = /antd\/.*?\/style\/css.*?/
const origExternals = [...config.externals]
config.externals = [
(context, request, callback) => {
if (request.match(antStyles)) return callback()
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback)
} else {
callback()
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
]
module.exports = withCss() config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
})
}
return config
},
})
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"antd": "^3.9.2", "antd": "^3.9.2",
"babel-plugin-import": "^1.9.1", "babel-plugin-import": "^1.9.1",
"next": "latest", "next": "latest",
"null-loader": "2.0.0",
"react": "^16.7.0", "react": "^16.7.0",
"react-dom": "^16.7.0" "react-dom": "^16.7.0"
}, },
......
import Document, { Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
render () {
return (
<html>
<Head>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<meta charSet='utf-8' />
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
}
const withCSS = require('@zeit/next-css') const withCSS = require('@zeit/next-css')
// fix: prevents error when .css files are required by node module.exports = withCSS({
if (typeof require !== 'undefined') { webpack: (config, { isServer }) => {
// eslint-disable-next-line if (isServer) {
require.extensions['.css'] = file => {} const antStyles = /antd-mobile\/.*?\/style.*?/
} const origExternals = [...config.externals]
config.externals = [
(context, request, callback) => {
if (request.match(antStyles)) return callback()
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback)
} else {
callback()
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals)
]
module.exports = withCSS() config.module.rules.unshift({
test: antStyles,
use: 'null-loader'
})
}
return config
}
})
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"antd-mobile": "2.2.5", "antd-mobile": "2.2.5",
"babel-plugin-import": "^1.2.1", "babel-plugin-import": "^1.2.1",
"next": "latest", "next": "latest",
"null-loader": "2.0.0",
"react": "^16.7.0", "react": "^16.7.0",
"react-dom": "^16.7.0" "react-dom": "^16.7.0"
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment