Skip to content

Commit 98eb0ff

Browse files
committed
Update examples/with-antd-mobile
- Reduced noise - Simplify setup
1 parent f430796 commit 98eb0ff

File tree

13 files changed

+47
-399
lines changed

13 files changed

+47
-399
lines changed

examples/with-antd-mobile/.babelrc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
{
2-
"presets": [
3-
"next/babel"
4-
],
5-
"plugins": [
6-
[
7-
"import",
8-
{
9-
"libraryName": "antd-mobile"
10-
}
11-
]
12-
]
2+
"presets": ["next/babel"],
3+
"plugins": [
4+
["import", {
5+
"libraryName": "antd-mobile",
6+
"style": "css"
7+
}]
8+
]
139
}

examples/with-antd-mobile/components/Layout.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/with-antd-mobile/components/MenuBar.js

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,9 @@
1-
const path = require('path')
2-
const fs = require('fs')
3-
const requireHacker = require('require-hacker')
1+
const withCSS = require('@zeit/next-css')
42

5-
function setupRequireHacker () {
6-
const webjs = '.web.js'
7-
const webModules = ['antd-mobile', 'rmc-picker'].map(m => path.join('node_modules', m))
8-
9-
requireHacker.hook('js', filename => {
10-
if (filename.endsWith(webjs) || webModules.every(p => !filename.includes(p))) return
11-
12-
const webFilename = filename.replace(/\.js$/, webjs)
13-
if (!fs.existsSync(webFilename)) return
14-
15-
return fs.readFileSync(webFilename, { encoding: 'utf8' })
16-
})
17-
18-
requireHacker.hook('svg', filename => {
19-
return requireHacker.to_javascript_module_source(`#${path.parse(filename).name}`)
20-
})
21-
}
22-
23-
setupRequireHacker()
24-
25-
function moduleDir (m) {
26-
return path.dirname(require.resolve(`${m}/package.json`))
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) => {}
277
}
288

29-
module.exports = {
30-
webpack: (config, { dev }) => {
31-
config.resolve.extensions = ['.web.js', '.js', '.json']
32-
33-
config.module.rules.push(
34-
{
35-
test: /\.(svg)$/i,
36-
loader: 'emit-file-loader',
37-
options: {
38-
name: 'dist/[path][name].[ext]'
39-
},
40-
include: [
41-
moduleDir('antd-mobile'),
42-
__dirname
43-
]
44-
},
45-
{
46-
test: /\.(svg)$/i,
47-
loader: 'svg-sprite-loader',
48-
include: [
49-
moduleDir('antd-mobile'),
50-
__dirname
51-
]
52-
}
53-
)
54-
55-
return config
56-
}
57-
}
9+
module.exports = withCSS()

examples/with-antd-mobile/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
"name": "with-antd-mobile",
33
"version": "1.1.0",
44
"dependencies": {
5-
"antd-mobile": "1.4.0",
5+
"@zeit/next-css": "1.0.1",
6+
"antd-mobile": "2.2.5",
67
"babel-plugin-import": "^1.2.1",
78
"next": "latest",
89
"react": "^16.0.0",
9-
"react-dom": "^16.0.0",
10-
"require-hacker": "^3.0.0",
11-
"svg-sprite-loader": "0.3.1"
10+
"react-dom": "^16.0.0"
1211
},
1312
"scripts": {
1413
"dev": "next",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import App, { Container } from 'next/app'
3+
import Head from 'next/head'
4+
5+
export default class CustomApp extends App {
6+
render () {
7+
const { Component, pageProps } = this.props
8+
return (
9+
<Container>
10+
<Head>
11+
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no' />
12+
<style global jsx>{`
13+
html,
14+
body {
15+
font-family: "Helvetica Neue", "Hiragino Sans GB", Helvetica, "Microsoft YaHei", Arial;
16+
margin: 0;
17+
}
18+
`}</style>
19+
</Head>
20+
<Component {...pageProps} />
21+
</Container>
22+
)
23+
}
24+
}

examples/with-antd-mobile/pages/_document.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/with-antd-mobile/pages/home.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

examples/with-antd-mobile/pages/icon.js

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Component } from 'react'
1+
import { Button, WhiteSpace, WingBlank } from 'antd-mobile'
22

3-
export default class Index extends Component {
4-
static async getInitialProps ({ res }) {
5-
res.setHeader('Location', '/home')
6-
res.statusCode = 302
7-
res.end()
8-
}
9-
}
3+
export default () => (
4+
<WingBlank>
5+
<WhiteSpace />
6+
<Button>Welcome to next.js</Button>
7+
</WingBlank>
8+
)

0 commit comments

Comments
 (0)