Skip to content

Commit 1457878

Browse files
committed
feat(*): base href support for publishing to subfolder
1 parent 2dbac07 commit 1457878

24 files changed

+161
-92
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"jest": true
1616
},
1717
"globals": {
18-
"Promise": true
18+
"Promise": true,
19+
"APP_BASEHREF": true
1920
},
2021
"rules": {
2122
"prettier/prettier": [

.github/main.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [ master ]
10+
pull_request:
11+
branches: [ master ]
12+
13+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
14+
jobs:
15+
# This workflow contains a single job called "build"
16+
build:
17+
# The type of runner that the job will run on
18+
runs-on: ubuntu-latest
19+
20+
# Steps represent a sequence of tasks that will be executed as part of the job
21+
steps:
22+
- name: Setup Node
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: '10.x'
26+
27+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
28+
- name: Checkout Code
29+
uses: actions/checkout@v2
30+
31+
# Runs a single command using the runners shell
32+
- name: Install Dependencies
33+
run: npm install
34+
35+
- name: Deploy Build
36+
run: npm run deploy-build
37+
38+
# Runs a set of commands using the runners shell
39+
- name: Publish to GitHub Pages
40+
uses: JamesIves/[email protected]
41+
with:
42+
BRANCH: gh-pages
43+
FOLDER: dist
44+
CLEAN: true
45+
46+

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"liveServer.settings.root": "./dist"
2+
"liveServer.settings.root": "./"
33
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Admin Template for React
22

3-
[DEMO](https://admin-react.bndy.net/) - Type any account to log in
3+
[DEMO](https://bndynet.github.io/admin-template-for-react/) - Type any account to log in
44

5-
[![Netlify Status](https://api.netlify.com/api/v1/badges/f1d6e125-33e2-42a7-a97e-67a912d878af/deploy-status)](https://app.netlify.com/sites/admin-react/deploys)
5+
![](https://github.com/bndynet/admin-template-for-react/workflows/CI/badge.svg)
66
![](https://img.shields.io/badge/Language-TypeScript-blue.svg)
77
![](https://img.shields.io/badge/Language-SCSS-blue.svg)
88
![](https://img.shields.io/badge/React-16.3-brightgreen.svg?logo=react)

README.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[演示](https://admin-react.bndy.net/) - 输入任意字符,即可登录
44

5-
[![Netlify Status](https://api.netlify.com/api/v1/badges/f1d6e125-33e2-42a7-a97e-67a912d878af/deploy-status)](https://app.netlify.com/sites/admin-react/deploys)
5+
![](https://github.com/bndynet/admin-template-for-react/workflows/CI/badge.svg)
66
![](https://img.shields.io/badge/Language-TypeScript-blue.svg)
77
![](https://img.shields.io/badge/Language-SCSS-blue.svg)
88
![](https://img.shields.io/badge/React-16.3-brightgreen.svg?logo=react)

assets/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
1414
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
1515
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/animate.min.css" />
16-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous" />
16+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css" />
1717

18-
<!-- Global site tag (gtag.js) - Google Analytics -->
18+
<!-- Global site tag (gtag.js) - Google Analytics
1919
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-93843808-3"></script>
2020
<script>
2121
window.dataLayer = window.dataLayer || [];
@@ -24,6 +24,7 @@
2424
2525
gtag('config', 'UA-93843808-3');
2626
</script>
27+
-->
2728
</head>
2829

2930
<body>

package-lock.json

+13-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"start": "webpack-dev-server --open --config webpack.config.dev.js",
99
"build": "webpack --config webpack.config.prod.js",
10+
"deploy-build": "webpack --config webpack.config.prod.js --env.baseHref=/admin-template-for-react/",
1011
"format": "prettier --write ./src/**",
1112
"lint": "eslint ./src/**/*.{ts,tsx} || stylelint ./src/**/*.{scss,css}",
1213
"precommit": "lint-staged",
@@ -62,7 +63,7 @@
6263
"@types/react": "^16.8.17",
6364
"@types/react-dom": "^16.8.3",
6465
"@types/react-redux": "^6.0.14",
65-
"@types/react-router-config": "^1.1.2",
66+
"@types/react-router-config": "^5.0.1",
6667
"@types/react-router-dom": "^4.3.1",
6768
"@types/recharts": "file:local-types/recharts",
6869
"@types/redux-logger": "^3.0.7",
@@ -71,6 +72,7 @@
7172
"autoprefixer": "^9.5.0",
7273
"awesome-typescript-loader": "^5.2.1",
7374
"babel-loader": "^8.0.4",
75+
"base-href-webpack-plugin": "^2.0.0",
7476
"clean-webpack-plugin": "^1.0.1",
7577
"copy-webpack-plugin": "^4.6.0",
7678
"css-loader": "^1.0.1",

src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import _merge from 'lodash-es/merge';
33
import { connect } from 'react-redux';
44
import { Dispatch, Action } from 'redux';
5-
import { renderRoutes } from 'react-router-config';
65

76
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
87
import {
@@ -19,6 +18,7 @@ import { actions as globalActions } from 'app/service/global';
1918
import { KEY_THEME } from 'app/theme';
2019
import storage from 'app/helpers/storage';
2120
import { onAppInit } from './app.events';
21+
import utils from './helpers/utils';
2222

2323
const styles = (theme: Theme) => {
2424
return createStyles({
@@ -91,7 +91,7 @@ class App extends React.Component<AppComponentProps, AppComponentState> {
9191
<Overlay open={this.props.loading}>
9292
<Loading loadingText={this.props.loadingText} />
9393
</Overlay>
94-
{renderRoutes(routes)}
94+
{utils.renderRoutes(routes)}
9595
</MuiThemeProvider>
9696
</div>
9797
)

src/config/app.common.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Config } from '.';
33
const config: Config = {
44
title: 'admin.brand',
55
logoUri: 'https://static.bndy.net/images/logo_white.svg',
6-
resourceBaseUri: '/',
6+
resourceBaseUri: APP_BASEHREF || '/',
77
defaultLocale: 'zh-CN', // empty to use navigator language
88
locales: [
99
{

src/config/menus.admin.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,37 @@ import PeopleIcon from '@material-ui/icons/People';
66
import BarChartIcon from '@material-ui/icons/BarChart';
77
import LayersIcon from '@material-ui/icons/Layers';
88
import { MenuItem } from 'app/types';
9-
import utils from 'app/helpers/utils';
109

1110
const menus: MenuItem[] = [
1211
{
13-
icon: 'fas fa-home',
12+
icon: 'fa fa-home',
1413
text: 'Home',
1514
description: 'Go to public home',
16-
link: utils.link(),
15+
link: '',
1716
},
1817
{
19-
icon: 'fas fa-tachometer-alt',
18+
icon: 'fa fa-tachometer',
2019
text: 'Dashboard',
2120
description: '',
22-
link: utils.link('admin/dashboard'),
21+
link: '/admin/dashboard',
2322
},
2423
{
25-
icon: 'fas fa-edit',
24+
icon: 'fa fa-edit',
2625
text: 'Markdown',
2726
description: '',
28-
link: utils.link('admin/markdown'),
27+
link: '/admin/markdown',
2928
},
3029
{
31-
icon: 'fas fa-table',
30+
icon: 'fa fa-table',
3231
text: 'DataTable',
3332
description: '',
34-
link: utils.link('admin/examples/datatable'),
33+
link: '/admin/examples/datatable',
3534
},
3635
{
37-
icon: 'fas fa-exclamation-triangle',
36+
icon: 'fa fa-exclamation-triangle',
3837
text: '404 Page',
3938
description: '',
40-
link: utils.link('admin/this_page_not_found'),
39+
link: '/admin/this_page_not_found',
4140
},
4241
{
4342
icon: <DnsIcon />,

src/config/menus.user.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { MenuItem } from 'app/types';
2-
import utils from 'app/helpers/utils';
32

43
const menus: MenuItem[] = [
54
{
6-
icon: 'fas fa-user-cog',
5+
icon: 'fa fa-cogs',
76
text: 'Settings',
8-
link: utils.link('settings'),
7+
link: '/settings',
98
},
109
{
11-
icon: 'fas fa-sign-out-alt',
10+
icon: 'fa fa-sign-out',
1211
text: 'Log out',
13-
link: utils.link('logout'),
12+
link: '/logout',
1413
},
1514
];
1615

src/config/routes.admin.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { Dashboard, Markdown, DataTableExample } from 'app/pages/admin';
22
import { NotFound } from 'app/pages/public';
3-
import utils from 'app/helpers/utils';
43

54
const routes = [
65
{
7-
path: utils.link('admin'),
6+
path: '/admin',
87
exact: true,
98
component: Dashboard,
109
},
1110
{
12-
path: utils.link('admin/dashboard'),
11+
path: '/admin/dashboard',
1312
exact: true,
1413
component: Dashboard,
1514
},
1615
{
17-
path: utils.link('admin/markdown'),
16+
path: '/admin/markdown',
1817
exact: true,
1918
component: Markdown,
2019
},
2120
{
22-
path: utils.link('admin/examples/datatable'),
21+
path: '/admin/examples/datatable',
2322
exact: true,
2423
component: DataTableExample,
2524
},

src/config/routes.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import { isAuthorized, getAuthUri } from 'app/service/auth';
44
import { Home, NotFound } from 'app/pages/public';
55
import { Admin } from 'app/pages/admin';
66
import { Login, Logout, Callback } from 'app/pages/auth';
7-
import utils from 'app/helpers/utils';
7+
import { RouteConfig } from 'react-router-config';
88

9-
const routes = [
9+
const routes: RouteConfig[] = [
1010
{
11-
path: utils.link(),
11+
path: '/',
1212
exact: true,
1313
component: Home,
1414
},
1515
{
16-
path: utils.link('login'),
16+
path: '/login',
1717
component: Login,
1818
},
1919
{
20-
path: utils.link('logout'),
20+
path: '/logout',
2121
component: Logout,
2222
},
2323
{
24-
path: utils.link('auth/callback'),
24+
path: '/auth/callback',
2525
component: Callback,
2626
},
2727
{
28-
path: utils.link('admin'),
28+
path: '/admin',
2929
// `render()` method support in react-router-config v5.0
3030
/* eslint-disable */
3131
render: () => {

src/globals.d.tsx src/global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare const APP_NAME: string;
22
declare const APP_VERSION: string;
33
declare const APP_BUILD: string;
4-
declare const APP_ROOT: string;
4+
declare const APP_BASEHREF: string;
55

66
interface Window {
77
__APP_CONF__: any;

0 commit comments

Comments
 (0)