Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Commit 00a1405

Browse files
committed
chore: Upgrade webpack config.
1 parent c7b2944 commit 00a1405

File tree

37 files changed

+411
-226
lines changed

37 files changed

+411
-226
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ export const mocker = {
149149
}
150150
```
151151

152+
### Home Page
153+
154+
Add `homepage` to `package.json`
155+
156+
> The step below is important!
157+
158+
Open your package.json and add a homepage field for your project:
159+
160+
```json
161+
"homepage": "https://myusername.github.io/my-app",
162+
```
163+
164+
or for a GitHub user page:
165+
166+
```json
167+
"homepage": "https://myusername.github.io",
168+
```
169+
170+
or for a custom domain page:
171+
172+
```json
173+
"homepage": "https://mywebsite.com",
174+
```
175+
176+
KKT uses the `homepage` field to determine the root URL in the built HTML file.
177+
152178
### Loaders
153179

154180
- [@kkt/loader-less](https://github.com/kktjs/kkt-next/tree/master/packages/kkt-loader-less)

example/basic/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "basic-example",
2+
"name": "@kkt/template-basic",
33
"version": "1.0.0",
44
"description": "The react base application.",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/basic",
65
"private": true,
76
"scripts": {
87
"start": "kkt start",
@@ -21,9 +20,6 @@
2120
"react": "^16.12.0",
2221
"react-dom": "^16.12.0"
2322
},
24-
"devDependencies": {
25-
"kkt": "file:../../packages/kkt-core"
26-
},
2723
"eslintConfig": {
2824
"extends": "react-app"
2925
},
@@ -38,5 +34,8 @@
3834
"last 1 firefox version",
3935
"last 1 safari version"
4036
]
37+
},
38+
"devDependencies": {
39+
"kkt": "5.4.3"
4140
}
4241
}

example/basic/src/serviceWorker.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This optional code is used to register a service worker.
2+
// register() is not called by default.
3+
4+
// This lets the app load faster on subsequent visits in production, and gives
5+
// it offline capabilities. However, it also means that developers (and users)
6+
// will only see deployed updates on subsequent visits to a page, after all the
7+
// existing tabs open on the page have been closed, since previously cached
8+
// resources are updated in the background.
9+
10+
// To learn more about the benefits of this model and instructions on how to
11+
// opt-in, read https://bit.ly/CRA-PWA
12+
13+
const isLocalhost = Boolean(
14+
window.location.hostname === 'localhost' ||
15+
// [::1] is the IPv6 localhost address.
16+
window.location.hostname === '[::1]' ||
17+
// 127.0.0.0/8 are considered localhost for IPv4.
18+
window.location.hostname.match(
19+
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20+
)
21+
);
22+
23+
export function register(config) {
24+
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25+
// The URL constructor is available in all browsers that support SW.
26+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27+
if (publicUrl.origin !== window.location.origin) {
28+
// Our service worker won't work if PUBLIC_URL is on a different origin
29+
// from what our page is served on. This might happen if a CDN is used to
30+
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
31+
return;
32+
}
33+
34+
window.addEventListener('load', () => {
35+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36+
37+
if (isLocalhost) {
38+
// This is running on localhost. Let's check if a service worker still exists or not.
39+
checkValidServiceWorker(swUrl, config);
40+
41+
// Add some additional logging to localhost, pointing developers to the
42+
// service worker/PWA documentation.
43+
navigator.serviceWorker.ready.then(() => {
44+
console.log(
45+
'This web app is being served cache-first by a service ' +
46+
'worker. To learn more, visit https://bit.ly/CRA-PWA'
47+
);
48+
});
49+
} else {
50+
// Is not localhost. Just register service worker
51+
registerValidSW(swUrl, config);
52+
}
53+
});
54+
}
55+
}
56+
57+
function registerValidSW(swUrl, config) {
58+
navigator.serviceWorker
59+
.register(swUrl)
60+
.then(registration => {
61+
registration.onupdatefound = () => {
62+
const installingWorker = registration.installing;
63+
if (installingWorker == null) {
64+
return;
65+
}
66+
installingWorker.onstatechange = () => {
67+
if (installingWorker.state === 'installed') {
68+
if (navigator.serviceWorker.controller) {
69+
// At this point, the updated precached content has been fetched,
70+
// but the previous service worker will still serve the older
71+
// content until all client tabs are closed.
72+
console.log(
73+
'New content is available and will be used when all ' +
74+
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75+
);
76+
77+
// Execute callback
78+
if (config && config.onUpdate) {
79+
config.onUpdate(registration);
80+
}
81+
} else {
82+
// At this point, everything has been precached.
83+
// It's the perfect time to display a
84+
// "Content is cached for offline use." message.
85+
console.log('Content is cached for offline use.');
86+
87+
// Execute callback
88+
if (config && config.onSuccess) {
89+
config.onSuccess(registration);
90+
}
91+
}
92+
}
93+
};
94+
};
95+
})
96+
.catch(error => {
97+
console.error('Error during service worker registration:', error);
98+
});
99+
}
100+
101+
function checkValidServiceWorker(swUrl, config) {
102+
// Check if the service worker can be found. If it can't reload the page.
103+
fetch(swUrl, {
104+
headers: { 'Service-Worker': 'script' }
105+
})
106+
.then(response => {
107+
// Ensure service worker exists, and that we really are getting a JS file.
108+
const contentType = response.headers.get('content-type');
109+
if (
110+
response.status === 404 ||
111+
(contentType != null && contentType.indexOf('javascript') === -1)
112+
) {
113+
// No service worker found. Probably a different app. Reload the page.
114+
navigator.serviceWorker.ready.then(registration => {
115+
registration.unregister().then(() => {
116+
window.location.reload();
117+
});
118+
});
119+
} else {
120+
// Service worker found. Proceed as normal.
121+
registerValidSW(swUrl, config);
122+
}
123+
})
124+
.catch(() => {
125+
console.log(
126+
'No internet connection found. App is running in offline mode.'
127+
);
128+
});
129+
}
130+
131+
export function unregister() {
132+
if ('serviceWorker' in navigator) {
133+
navigator.serviceWorker.ready
134+
.then(registration => {
135+
registration.unregister();
136+
})
137+
.catch(error => {
138+
console.error(error.message);
139+
});
140+
}
141+
}

example/basic/src/setupTests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom/extend-expect';

example/bundle/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "bundle-example",
2+
"name": "@kkt/template-bundle",
33
"version": "1.0.0",
44
"description": "",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/bundle",
65
"private": true,
76
"scripts": {
87
"start": "kkt start",
@@ -25,8 +24,8 @@
2524
"react-dom": "^16.12.0"
2625
},
2726
"devDependencies": {
28-
"@kkt/loader-less": "^5.3.0",
29-
"kkt": "file:../../packages/kkt-core"
27+
"@kkt/loader-less": "5.4.3",
28+
"kkt": "5.4.3"
3029
},
3130
"eslintConfig": {
3231
"extends": "react-app"

example/electron/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "electron-example",
2+
"name": "@kkt/template-electron",
33
"version": "1.0.0",
44
"description": "Electron example.",
55
"main": "app/main.js",
6-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/electron",
6+
"private": true,
77
"scripts": {
88
"start": "kkt start --port 1909",
99
"build": "kkt build",
@@ -24,7 +24,7 @@
2424
"@types/react": "^16.9.13",
2525
"@types/react-dom": "^16.9.4",
2626
"electron": "^6.1.5",
27-
"kkt": "file:../../packages/kkt-core"
27+
"kkt": "5.4.3"
2828
},
2929
"dependencies": {
3030
"react": "^16.12.0",

example/less/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "less-example",
2+
"name": "@uiw/template-less",
33
"version": "1.0.0",
44
"description": "",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/less",
65
"private": true,
76
"scripts": {
87
"start": "kkt start",
@@ -19,8 +18,8 @@
1918
"react-dom": "^16.12.0"
2019
},
2120
"devDependencies": {
22-
"@kkt/loader-less": "^5.3.0",
23-
"kkt": "file:../../packages/kkt-core"
21+
"@kkt/loader-less": "5.4.3",
22+
"kkt": "5.4.3"
2423
},
2524
"eslintConfig": {
2625
"extends": "react-app"

example/markdown/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "markdown",
2+
"name": "@kkt/template-markdown",
33
"version": "1.0.0",
44
"description": "",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/markdown",
65
"private": true,
76
"scripts": {
87
"start": "kkt start",
@@ -19,7 +18,7 @@
1918
"react-dom": "^16.12.0"
2019
},
2120
"devDependencies": {
22-
"kkt": "file:../../packages/kkt-core",
21+
"kkt": "5.4.3",
2322
"raw-loader": "^1.0.0"
2423
},
2524
"eslintConfig": {

example/react-component-tsx/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "react-component-tsx-example",
2+
"name": "@kkt/template-react-component-tsx",
33
"version": "1.0.0",
44
"description": "React Component Example for TypeScript.",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/react-component-tsx",
5+
"private": true,
66
"main": "lib/cjs/index.js",
77
"module": "lib/esm/index.js",
88
"scripts": {
@@ -36,12 +36,12 @@
3636
"react-dom": "^16.12.0"
3737
},
3838
"devDependencies": {
39-
"@kkt/loader-less": "^5.3.0",
39+
"@kkt/loader-less": "5.4.3",
4040
"@types/classnames": "^2.2.9",
4141
"@types/react": "^16.9.11",
4242
"@types/react-dom": "^16.9.4",
4343
"compile-less-cli": "^1.1.5",
44-
"kkt": "file:../../packages/kkt-core",
44+
"kkt": "5.4.3",
4545
"raw-loader": "^3.1.0",
4646
"tsbb": "^1.3.5"
4747
},

example/react-component/package.json

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
{
2-
"name": "react-component-example",
3-
"version": "1.0.0",
4-
"description": "React Component Example.",
5-
"homepage": "https://github.com/kktjs/kkt-next/tree/master/example/react-component",
6-
"private": true,
2+
"name": "@kkt/template-react-component",
3+
"version": "1.0.0",
4+
"description": "React Component Example.",
5+
"private": true,
76
"scripts": {
87
"start": "kkt start",
98
"build": "kkt build"
109
},
11-
"repository": {
12-
"type": "git",
13-
"url": "https://github.com/kktjs/kkt-next.git"
14-
},
15-
"author": "",
16-
"license": "MIT",
17-
"dependencies": {
18-
"@kkt/button": "file:./button",
19-
"react": "^16.12.0",
20-
"react-dom": "^16.12.0"
21-
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/kktjs/kkt-next.git"
13+
},
14+
"author": "",
15+
"license": "MIT",
16+
"dependencies": {
17+
"@kkt/button": "file:./button",
18+
"react": "^16.12.0",
19+
"react-dom": "^16.12.0"
20+
},
2221
"devDependencies": {
23-
"@kkt/loader-less": "^5.3.0",
24-
"kkt": "file:../../packages/kkt-core"
25-
},
26-
"eslintConfig": {
27-
"extends": "react-app"
22+
"@kkt/loader-less": "5.4.3",
23+
"kkt": "5.4.3"
2824
},
29-
"browserslist": {
30-
"production": [
31-
">0.2%",
32-
"not dead",
33-
"not op_mini all"
34-
],
35-
"development": [
36-
"last 1 chrome version",
37-
"last 1 firefox version",
38-
"last 1 safari version"
39-
]
40-
}
25+
"eslintConfig": {
26+
"extends": "react-app"
27+
},
28+
"browserslist": {
29+
"production": [
30+
">0.2%",
31+
"not dead",
32+
"not op_mini all"
33+
],
34+
"development": [
35+
"last 1 chrome version",
36+
"last 1 firefox version",
37+
"last 1 safari version"
38+
]
39+
}
4140
}

0 commit comments

Comments
 (0)