Skip to content

Commit 6f1c03f

Browse files
committed
feat: add example
1 parent 14bd03a commit 6f1c03f

19 files changed

+209
-140
lines changed

.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
"no-lonely-if": "off",
131131
"no-param-reassign": "off",
132132
"no-alert": "off",
133+
"no-plusplus": "off",
134+
"no-await-in-loop": "off",
133135
"no-shadow": [
134136
"off",
135137
{

build/client/utils.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ const theme = path.join(__dirname, '../../src/client/style/antd.override.theme.l
55

66
const config = require('../../config')
77

8-
exports.resolve = function(dir) {
8+
exports.resolve = function (dir) {
99
return path.join(__dirname, '../../', dir)
1010
}
1111

12-
exports.assetsPath = function(_path) {
12+
exports.assetsPath = function (_path) {
1313
const assetsSubDirectory = config.base.assetsSubDirectory
1414
return path.posix.join(assetsSubDirectory, _path)
1515
}
1616

17-
exports.styleLoaders = function(options) {
17+
exports.styleLoaders = function (options) {
1818
const baseLoaders = [
1919
{
20-
loader:'isomorphic-style-loader'
20+
loader: 'isomorphic-style-loader'
2121
},
2222
{
23-
loader: 'css-loader',
23+
loader: 'css-loader'
2424
},
2525
{ loader: 'postcss-loader' }
2626
]
@@ -41,7 +41,7 @@ exports.styleLoaders = function(options) {
4141
include: /node_modules\/antd/,
4242
use: [
4343
{
44-
loader:'isomorphic-style-loader'
44+
loader: 'isomorphic-style-loader'
4545
},
4646
{
4747
loader: 'css-loader'
@@ -63,7 +63,14 @@ exports.styleLoaders = function(options) {
6363
test: /\.css$/,
6464
include: /node_modules/,
6565
use: [
66-
options.extract ? MiniCssExtractPlugin.loader : 'style-loader',
66+
options.extract
67+
? {
68+
loader: MiniCssExtractPlugin.loader,
69+
options: {
70+
publicPath: config.prod.assetsPublicPath
71+
}
72+
}
73+
: 'style-loader',
6774
{ loader: 'css-loader' }
6875
]
6976
})

build/client/webpack.prod.conf.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const os = require('os')
22
const path = require('path')
3-
const merge = require('webpack-merge')
3+
const { merge } = require('webpack-merge')
44
const TerserPlugin = require('terser-webpack-plugin')
55
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
66
const CompressionWebpackPlugin = require('compression-webpack-plugin')
@@ -10,6 +10,8 @@ const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
1010
const utils = require('./utils')
1111
const config = require('../../config')
1212
const baseWebpackConfig = require('./webpack.base.conf')
13+
//生成 manifest 方便定位对应的资源文件
14+
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
1315

1416
module.exports = merge(baseWebpackConfig, {
1517
mode: 'production',
@@ -27,10 +29,12 @@ module.exports = merge(baseWebpackConfig, {
2729

2830
plugins: [
2931
new MiniCssExtractPlugin({
30-
path: config.base.assetsRoot,
31-
publicPath: config.prod.assetsPublicPath,
3232
filename: utils.assetsPath('css/[name].[hash]p.css'),
3333
chunkFilename: utils.assetsPath('css/[id].[chunkhash]p.css')
34+
}),
35+
//生成 manifest 方便定位对应的资源文件
36+
new WebpackManifestPlugin({
37+
fileName: '../server/asset-manifest.json'
3438
})
3539
],
3640

@@ -44,12 +48,7 @@ module.exports = merge(baseWebpackConfig, {
4448
}
4549
}),
4650
new TerserPlugin({
47-
sourceMap: true,
48-
terserOptions: {
49-
compress: {
50-
drop_console: true
51-
}
52-
}
51+
parallel: true
5352
}),
5453
new CompressionWebpackPlugin({
5554
compressionOptions: {

config/base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var path = require('path')
22

33
module.exports = {
4-
title: 'react-ssr',
5-
projectName: 'ninth-studio-mobile',
4+
title: 'noov.js',
5+
projectName: 'static',
66
assetsPublicPath: 'http://localhost:8080/', // 设计到热更新的host jsonp客户端的地址
77
assetsSubDirectory: 'static',
88
assetsRoot: path.resolve(__dirname, '../dist')

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"less": "^4.1.1",
115115
"less-loader": "^8.1.1",
116116
"lint-staged": "^10.5.4",
117-
"mini-css-extract-plugin": "^1.5.0",
117+
"mini-css-extract-plugin": "^0.5.0",
118118
"oock": "^1.0.13",
119119
"optimize-css-assets-webpack-plugin": "^5.0.4",
120120
"postcss-loader": "^5.2.0",
@@ -134,6 +134,7 @@
134134
"webpack-cli": "^4.6.0",
135135
"webpack-dev-middleware": "^4.1.0",
136136
"webpack-hot-middleware": "^2.25.0",
137+
"webpack-manifest-plugin": "^3.1.1",
137138
"webpack-merge": "^5.7.3",
138139
"webpack-node-externals": "^3.0.0",
139140
"webpackbar": "^5.0.0-3"

src/client/main/layout.less

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
body {
2-
background-color: #f4f5f5;
2+
background-color: #fff;
33
}
44

5-
.layout-box {
6-
max-width: 750px;
7-
margin: 0 auto;
5+
h1 {
86
text-align: center;
9-
background: #fff;
10-
padding-left: 20px;
11-
padding-right: 20px;
12-
padding-top: 20px;
13-
14-
h1 {
15-
margin-top: 20px;
16-
}
7+
margin-top: 20px;
178
}

src/client/main/layout.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ interface IProps {}
99
class Index extends React.PureComponent<Istate, IProps> {
1010
render() {
1111
const { children } = this.props
12-
return (
13-
<div className="layout-box">
14-
<h1>ssr-layout</h1>
15-
{children}
16-
</div>
17-
)
12+
return <div className="layout-box">{children}</div>
1813
}
1914
}
2015

src/client/main/route-config.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ function pageNotFound({ staticContext }: any) {
2323
)
2424
}
2525
try {
26-
if (require.context) {
27-
const context = require.context(`../modules`, true, /.*\/routes\.tsx?$/)
28-
context.keys().forEach((key: string) => {
29-
const route = context(key).default
30-
routes = routes.concat(route)
31-
})
32-
}
26+
// if (require.context) {
27+
const context = require.context(`../modules`, true, /.*\/routes\.tsx?$/)
28+
context.keys().forEach((key: string) => {
29+
const route = context(key).default
30+
routes = routes.concat(route)
31+
})
32+
// }
3333
} catch (err) {
3434
console.warn(err.message)
3535
}

src/client/modules/about/index.less

-3
This file was deleted.

src/client/modules/about/index.tsx

-34
This file was deleted.

src/client/modules/about/routes.tsx

-9
This file was deleted.

src/client/modules/home/index.less

+87-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1-
.home {
2-
background-color: aquamarine;
1+
html {
2+
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
3+
'Helvetica Neue', Arial, sans-serif;
4+
font-size: 16px;
5+
word-spacing: 1px;
6+
-ms-text-size-adjust: 100%;
7+
-webkit-text-size-adjust: 100%;
8+
-moz-osx-font-smoothing: grayscale;
9+
-webkit-font-smoothing: antialiased;
10+
box-sizing: border-box;
11+
}
12+
13+
*,
14+
*::before,
15+
*::after {
16+
box-sizing: border-box;
17+
margin: 0;
18+
}
19+
20+
.button--green {
21+
display: inline-block;
22+
border-radius: 4px;
23+
border: 1px solid #3b8070;
24+
color: #3b8070;
25+
text-decoration: none;
26+
padding: 10px 30px;
27+
}
28+
29+
.button--green:hover {
30+
color: #fff;
31+
background-color: #3b8070;
32+
}
33+
34+
.button--grey {
35+
display: inline-block;
36+
border-radius: 4px;
37+
border: 1px solid #35495e;
38+
color: #35495e;
39+
text-decoration: none;
40+
padding: 10px 30px;
41+
margin-left: 15px;
42+
}
43+
44+
.button--grey:hover {
45+
color: #fff;
46+
background-color: #35495e;
47+
}
48+
49+
.container {
50+
margin: 0 auto;
51+
min-height: 100vh;
52+
display: flex;
53+
justify-content: center;
54+
// align-items: center;
55+
text-align: center;
56+
}
57+
58+
.title {
59+
font-family: 'Quicksand', 'Source Sans Pro', -apple-system, BlinkMacSystemFont,
60+
'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
61+
display: block;
62+
font-weight: 300;
63+
font-size: 100px;
64+
color: #35495e;
65+
letter-spacing: 1px;
66+
}
67+
68+
.subtitle {
69+
font-weight: 300;
70+
font-size: 42px;
71+
color: #526488;
72+
word-spacing: 5px;
73+
padding-bottom: 15px;
74+
}
75+
76+
.links {
77+
padding-top: 15px;
78+
}
79+
80+
.click-btn {
81+
margin-top: 20px;
82+
}
83+
84+
img {
85+
width: 200px;
86+
height: 100px;
87+
margin-top: 120px;
388
}

src/client/modules/home/index.tsx

+33-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,46 @@ import React from 'react'
22
import { Link } from 'react-router-dom'
33
import style from './index.less'
44
import isConnect from '@/library/isConnect'
5+
import Logo from './logo.jpg'
56

67
export const Home = () => {
78
const handleClick = () => {
89
alert('handleClick')
910
}
1011

1112
return (
12-
<div className="home">
13-
<h1>hello react-ssr</h1>
14-
<button onClick={handleClick}>click me1的顶顶顶顶顶的</button>
15-
{[22, 44, 55, 300, 100, 201].map((item: number) => (
16-
<div key={item}>{item}</div>
17-
))}
18-
<p>11</p>
19-
<Link to="/history">404 page</Link>
13+
<div className="container">
14+
<div>
15+
<img src={Logo} alt="" />
16+
<h1 className="title">noov for ssr</h1>
17+
<div className="links">
18+
<a
19+
href="https://art-design-ui.github.io/noov.js/"
20+
target="_blank"
21+
rel="noopener noreferrer"
22+
className="button--green"
23+
>
24+
Documentation
25+
</a>
26+
<a
27+
href="https://github.com/art-design-ui/noov.js"
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
className="button--grey"
31+
>
32+
5 GitHub
33+
</a>
34+
</div>
35+
<div
36+
role="button"
37+
tabIndex={0}
38+
className="button--green click-btn"
39+
onClick={handleClick}
40+
onKeyDown={handleClick}
41+
>
42+
点一点
43+
</div>
44+
</div>
2045
</div>
2146
)
2247
}

src/client/modules/home/logo.jpg

63.5 KB
Loading

0 commit comments

Comments
 (0)