Skip to content

Commit 05126d3

Browse files
committed
[WIP] Use new js-dom-router and add dynamic import support
1 parent 9979ef1 commit 05126d3

File tree

10 files changed

+35
-8637
lines changed

10 files changed

+35
-8637
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["@babel/plugin-syntax-dynamic-import"]
3+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test": "run-s -c lint"
1717
},
1818
"devDependencies": {
19+
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
1920
"browser-sync": "^2.26.5",
2021
"browser-sync-webpack-plugin": "2.0.1",
2122
"cross-env": "^5.2.0",
@@ -33,6 +34,7 @@
3334
"dependencies": {
3435
"bootstrap": "^4.3.1",
3536
"jquery": "^3.4.0",
37+
"js-dom-router": "^1.0.0",
3638
"popper.js": "^1.15.0"
3739
}
3840
}

resources/assets/scripts/app.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
*/
44
import 'jquery';
55
import 'bootstrap';
6+
import { router } from 'js-dom-router';
67

78
/**
8-
* Local Dependencies
9+
* DOM-based routing
910
*/
10-
import Router from './util/Router';
11-
import common from './routes/common';
12-
import aboutUs from './routes/about';
13-
import { ready } from './utils';
11+
import about from './routes/about';
1412

1513
/**
16-
* Populate the Router instance with DOM routes.
14+
* Below is an example of a dynamic import; it will not be loaded until it's needed.
1715
*
18-
* common – Fired on all pages.
19-
* aboutUs – Fired on the About Us page, note the change from about-us to aboutUs (camelCase).
16+
* See: {@link https://webpack.js.org/guides/code-splitting/#dynamic-imports | Dynamic Imports}
2017
*/
21-
const routes = new Router({
22-
common,
23-
aboutUs,
24-
});
18+
const home = async () => import(/* webpackChunkName: "home-page" */ './routes/home');
2519

2620
/**
27-
* Load Events
21+
* Set up DOM router
22+
*
23+
* .on(<name of body class>, callback)
24+
*
25+
* See: {@link http://goo.gl/EUTi53 | Markup-based Unobtrusive Comprehensive DOM-ready Execution} by Paul Irish
2826
*/
29-
ready(() => routes.loadEvents());
27+
router
28+
.on('about-us', about)
29+
.on('home', async (event) => (await home()).default(event))
30+
.ready();
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
/**
22
* About Us
3-
*
4-
* init – Fired on About Us page.
5-
* finalized – Fired on About Us page, after page specific JS is fired.
63
*/
7-
export default {
8-
init() {
9-
//
10-
},
11-
finalize() {
12-
//
13-
},
4+
export default () => {
5+
//--
146
};

resources/assets/scripts/routes/common.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Home
3+
*/
4+
export default () => {
5+
//--
6+
};

resources/assets/scripts/util/Router.js

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

resources/assets/scripts/util/camelCase.js

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

webpack.mix.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ const src = path => `resources/assets/${path}`;
1818
*/
1919

2020
// Public Path
21-
mix.setPublicPath('./dist');
21+
// Public Path
22+
mix
23+
.setPublicPath('./dist')
24+
.setResourceRoot(`/app/themes/sage/${mix.config.publicPath}/`)
25+
.webpackConfig({
26+
output: { publicPath: mix.config.resourceRoot }
27+
});
2228

2329
// Browsersync
2430
mix.browserSync({

0 commit comments

Comments
 (0)