File tree 13 files changed +168
-24
lines changed 13 files changed +168
-24
lines changed Original file line number Diff line number Diff line change 2
2
3
3
> React template for web app, powered by [ Poi] ( https://poi.js.org/ ) .
4
4
5
- - [x] prettier + eslint
6
- - [x] PWA
5
+ - [x] [ prettier] ( https://github.com/prettier/prettier ) + eslint
6
+ - [x] PWA support (by [ offline-plugin] ( https://github.com/NekR/offline-plugin ) )
7
+ - [x] [ TailwindCSS] ( https://tailwindcss.com/ ) & SASS
8
+ - [x] Routing & code splitting (by [ curi] ( https://github.com/pshrmn/curi ) )
7
9
8
10
## Usage
9
11
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ module.exports = {
17
17
type : 'confirm' ,
18
18
default : true ,
19
19
} ,
20
+ routing : {
21
+ message : 'Routing?' ,
22
+ type : 'confirm' ,
23
+ default : true ,
24
+ } ,
20
25
pwa : {
21
26
message : 'PWA support?' ,
22
27
type : 'confirm' ,
@@ -32,6 +37,9 @@ module.exports = {
32
37
'static/manifest.json' : 'pwa' ,
33
38
'tailwind.js' : 'tailwindcss' ,
34
39
'src/styles/tailwind.scss' : 'tailwindcss' ,
40
+ 'src/pages/**' : 'routing' ,
41
+ 'src/router/**' : 'routing' ,
42
+ 'src/App.css' : '!routing' ,
35
43
} ,
36
44
move : {
37
45
gitignore : '.gitignore' ,
Original file line number Diff line number Diff line change 7
7
"lint" : " eslint --ext .js,.jsx --ignore-path .gitignore ." ,
8
8
"lint:fix" : " eslint --fix --ext .js,.jsx --ignore-path .gitignore ."
9
9
},
10
- "dependencies" : {<% if (pwa) { %>
10
+ "dependencies" : {<% if (routing) { %>
11
+ "@curi/core" : " ^1.0.0-beta.35" ,
12
+ "@curi/react" : " ^1.0.0-beta.26" ,
13
+ "@curi/route-active" : " ^1.0.0-beta.6" ,
14
+ "@hickory/browser" : " ^1.0.0-beta.7" ,<% } %>
15
+ "loadable-components" : " 2.2.2" ,<% if (pwa) { %>
11
16
"offline-plugin" : " ^5.0.3" ,<% } %>
12
17
"react" : " ^16.4.0" ,
13
18
"react-dom" : " ^16.4.0"
34
39
"react-hot-loader" : " ^4.2.0" ,
35
40
"sass-loader" : " ^6.0.7" <% if(tailwindcss) { %>,
36
41
"tailwindcss" : " ^0.5.3" <% } %>
42
+ },
43
+ "resolutions" : {
44
+ "react" : " 16.4.0" ,
45
+ "react-dom" : " 16.4.0"
37
46
}
38
47
}
Original file line number Diff line number Diff line change 1
- import React , { Component } from 'react' ;
1
+ import React from 'react' ;
2
2
import { hot } from 'react-hot-loader' ;
3
+ < % if ( routing ) { % >
4
+ import { CuriProvider } from '@curi/react' ;
3
5
4
- import logo from './logo.svg' ;
6
+ const App = ( { router } ) => {
7
+ return (
8
+ < CuriProvider router = { router } >
9
+ { ( { response, router } ) => {
10
+ return (
11
+ < main >
12
+ < response . body
13
+ params = { response . params }
14
+ location = { response . location }
15
+ router = { router }
16
+ />
17
+ </ main >
18
+ ) ;
19
+ } }
20
+ </ CuriProvider >
21
+ ) ;
22
+ } ;
23
+ < % } else { % >
5
24
import './App.css' ;
6
25
7
- class App extends Component {
8
- render ( ) {
9
- return (
10
- < div className = "App" >
11
- < header className = "App-header" >
12
- < img src = { logo } className = "App-logo" alt = "logo" />
13
- < h1 className = "App-title" > Welcome to React</ h1 >
14
- </ header >
15
- < p className = "App-intro text-lg" >
16
- To get started, edit < code > src/App.js</ code > and save to reload.
17
- </ p >
18
- </ div >
19
- ) ;
20
- }
21
- }
22
-
26
+ const App = ( ) => {
27
+ return (
28
+ < div className = "App" >
29
+ < header className = "App-header" >
30
+ < h1 className = "App-title" > Welcome to React</ h1 >
31
+ </ header >
32
+ < p className = "App-intro text-xl" >
33
+ To get started, edit < code > src/App.js</ code > and save to reload.
34
+ </ p >
35
+ </ div >
36
+ ) ;
37
+ } ;
38
+ < % } % >
23
39
export default hot ( module ) ( App ) ;
Original file line number Diff line number Diff line change @@ -2,10 +2,19 @@ import React from 'react';
2
2
import ReactDOM from 'react-dom' ;
3
3
4
4
import './styles' ;
5
- import App from './App' ;
5
+ import App from './App' ; < % if ( routing ) { % >
6
+ import { setupRouter } from './router' ;
6
7
8
+ const makeRender = ( ) => ( { router } ) => {
9
+ ReactDOM . render ( < App router = { router } /> , document . getElementById ( 'app' ) ) ;
10
+ } ;
11
+
12
+ const router = setupRouter ( ) ;
13
+ router . respond ( makeRender ( ) ) ;
14
+ < % } else { % >
7
15
const render = Component => {
8
16
ReactDOM . render ( < Component /> , document . getElementById ( 'app' ) ) ;
9
17
} ;
10
18
11
19
render ( App ) ;
20
+ < % } % >
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ const NotFound = ( ) => {
4
+ return < div > NotFound</ div > ;
5
+ } ;
6
+
7
+ export default NotFound ;
Original file line number Diff line number Diff line change
1
+ .App {
2
+ text-align : center;
3
+ }
4
+
5
+ .App-logo {
6
+ animation : App-logo-spin infinite 20s linear;
7
+ height : 80px ;
8
+ }
9
+
10
+ .App-header {
11
+ background-color : # 222 ;
12
+ height : 150px ;
13
+ padding : 20px ;
14
+ color : white;
15
+ }
16
+
17
+ .App-title {
18
+ font-size : 1.5em ;
19
+ }
20
+
21
+ .App-intro {
22
+ font-size : large;
23
+ }
24
+
25
+ @keyframes App-logo-spin {
26
+ from { transform : rotate (0deg ); }
27
+ to { transform : rotate (360deg ); }
28
+ }
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+
3
+ import logo from './logo.svg' ;
4
+ import './Home.css' ;
5
+
6
+ class Home extends Component {
7
+ render ( ) {
8
+ return (
9
+ < div className = "App" >
10
+ < header className = "App-header" >
11
+ < img src = { logo } className = "App-logo" alt = "logo" />
12
+ < h1 className = "App-title" > Welcome to React</ h1 >
13
+ </ header >
14
+ < p className = "App-intro text-xl" >
15
+ To get started, edit < code > src/App.js</ code > and save to reload.
16
+ </ p >
17
+ </ div >
18
+ ) ;
19
+ }
20
+ }
21
+
22
+ export default Home ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
- import App from './App ' ;
3
+ import Home from './Home ' ;
4
4
5
5
it ( 'renders without crashing' , ( ) => {
6
6
const div = document . createElement ( 'div' ) ;
7
- ReactDOM . render ( < App /> , div ) ;
7
+ ReactDOM . render ( < Home /> , div ) ;
8
8
} ) ;
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ import Browser from '@hickory/browser' ;
2
+ import curi from '@curi/core' ;
3
+ import createActiveAddon from '@curi/route-active' ;
4
+
5
+ import getRoutes from './routes' ;
6
+
7
+ const history = Browser ( ) ;
8
+
9
+ export const setupRouter = ( ) => {
10
+ return curi ( history , getRoutes ( ) , {
11
+ route : [ createActiveAddon ( ) ] ,
12
+ } ) ;
13
+ } ;
Original file line number Diff line number Diff line change
1
+ import loadable from '@/utils/loadable' ;
2
+
3
+ const Home = loadable ( ( ) => import ( '@/pages/Home' ) ) ;
4
+ const NotFound = loadable ( ( ) => import ( '@/pages/404' ) ) ;
5
+
6
+ export default ( ) => {
7
+ return [
8
+ {
9
+ name : 'Home' ,
10
+ path : '' ,
11
+ response ( ) {
12
+ return {
13
+ body : Home ,
14
+ } ;
15
+ } ,
16
+ } ,
17
+ {
18
+ name : 'NotFound' ,
19
+ path : '(.*)' ,
20
+ response ( ) {
21
+ return {
22
+ body : NotFound ,
23
+ } ;
24
+ } ,
25
+ } ,
26
+ ] ;
27
+ } ;
Original file line number Diff line number Diff line change
1
+ import loadable from 'loadable-components' ;
2
+
3
+ export default loadable ;
You can’t perform that action at this time.
0 commit comments