Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
Update repo info
Browse files Browse the repository at this point in the history
  • Loading branch information
gvergnaud committed Feb 17, 2017
1 parent 9c19a97 commit 5f8a0cc
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 82 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ framework.

## Why ?

Next.js introduced in it's V2 a programatic routing API allowing you to serve your
Next.js introduced in it's V2 a programmatic routing API allowing you to serve your
Next app from, for example, an express server:

```js
Expand All @@ -16,7 +16,7 @@ server.get('/a', (req, res) => {
```
```jsx
// /index.js
<Link href="/a" as="/b"><a>Visit me!</a></Link>
<Link href="/b" as="/a"><a>Visit me!</a></Link>
```

But as the number of pages grows, it's getting a little hard to manage...
Expand Down Expand Up @@ -53,8 +53,9 @@ expressServer.use(dynamicRoutes.createMiddleware(nextApp))
Then Nextjs Dynamic Routes will generate for you every Link components you will
need! you just have to import them like this:

```js
import { UserLink, FilmLink } from 'nextjs-dynamic-routes'
```jsx
// pages/index.js
import { UserLink, FilmLink } from '../routes'

export default () => (
<div>
Expand All @@ -73,18 +74,19 @@ export default () => (
)
```

### Even cooler
### It works for static routes too

You can even import `Link` components that you didn't declare in your `routes.js`
config file! It's using an es6 Proxy for that and auto fill the `href` property
config file! It's using an es6 `Proxy` under the hood to auto-fill the `href` property
based on the name of the `Link` component you imported.

for exemple if you do:
```js
import { AboutLink } from 'nextjs-dynamic-routes'
// pages/index.js
import { AboutLink } from '../routes'
```
what you will actually get is:
```js
```jsx
props => <Link href="/about" {...props} />
```
Pretty cool huh?
50 changes: 30 additions & 20 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

Expand Down Expand Up @@ -63,7 +64,7 @@
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ return __webpack_require__(__webpack_require__.s = 8);
/******/ })
/************************************************************************/
/******/ ([
Expand Down Expand Up @@ -96,7 +97,7 @@ var mapKeys = function mapKeys(mapper) {
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__queryString__ = __webpack_require__(6);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__queryString__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__object__ = __webpack_require__(0);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return createLinkProps; });

Expand Down Expand Up @@ -125,28 +126,34 @@ var createLinkProps = function createLinkProps(_ref) {
/* 2 */
/***/ (function(module, exports) {

module.exports = require("lodash/fp");
module.exports = require("lodash/fp/capitalize");

/***/ }),
/* 3 */
/***/ (function(module, exports) {

module.exports = require("next/link");
module.exports = require("lodash/fp/compose");

/***/ }),
/* 4 */
/***/ (function(module, exports) {

module.exports = require("path-match");
module.exports = require("next/link");

/***/ }),
/* 5 */
/***/ (function(module, exports) {

module.exports = require("react");
module.exports = require("path-match");

/***/ }),
/* 6 */
/***/ (function(module, exports) {

module.exports = require("react");

/***/ }),
/* 7 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Expand Down Expand Up @@ -184,21 +191,23 @@ var fromString = function fromString(str) {
};

/***/ }),
/* 7 */
/* 8 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_path_match__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_path_match__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_path_match___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_path_match__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react__ = __webpack_require__(6);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_react__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_next_link__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_next_link__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_next_link___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_next_link__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_fp__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_fp___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_lodash_fp__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__utils_routing__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__utils_object__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_fp_capitalize__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_fp_capitalize___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_lodash_fp_capitalize__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_lodash_fp_compose__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_lodash_fp_compose___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_lodash_fp_compose__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__utils_routing__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__utils_object__ = __webpack_require__(0);
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };


Expand All @@ -208,6 +217,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument




var match = __WEBPACK_IMPORTED_MODULE_0_path_match___default()();

var log = function log(x) {
Expand Down Expand Up @@ -241,17 +251,17 @@ var createMiddleware = function createMiddleware(routes) {
};

var createLinks = function createLinks(routes) {
var links = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_lodash_fp__["compose"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_5__utils_object__["a" /* mapKeys */])(function (key) {
return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_lodash_fp__["capitalize"])(key) + 'Link';
}), __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_5__utils_object__["b" /* mapValues */])(function (mapProps) {
var links = __WEBPACK_IMPORTED_MODULE_4_lodash_fp_compose___default()(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__utils_object__["a" /* mapKeys */])(function (key) {
return __WEBPACK_IMPORTED_MODULE_3_lodash_fp_capitalize___default()(key) + 'Link';
}), __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__utils_object__["b" /* mapValues */])(function (mapProps) {
return function (props) {
return __WEBPACK_IMPORTED_MODULE_1_react___default.a.createElement(
__WEBPACK_IMPORTED_MODULE_2_next_link___default.a,
mapProps(props),
props.children
);
};
}), __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_5__utils_object__["b" /* mapValues */])(__WEBPACK_IMPORTED_MODULE_4__utils_routing__["a" /* createLinkProps */]))(routes);
}), __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_6__utils_object__["b" /* mapValues */])(__WEBPACK_IMPORTED_MODULE_5__utils_routing__["a" /* createLinkProps */]))(routes);

return new Proxy(links, {
get: function get(_, k) {
Expand All @@ -272,4 +282,4 @@ var createDynamicRoutes = function createDynamicRoutes(routesConfig) {
/* harmony default export */ __webpack_exports__["default"] = createDynamicRoutes;

/***/ })
/******/ ])));
/******/ ]);
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
{
"name": "nextjs-dynamic-routes",
"version": "1.0.0",
"version": "1.0.4",
"description": "Thin wrapper around Next.js's router to enable you to create dynamic routes.",
"main": "./dist/index.js",
"repository": "no",
"main": "dist/index.js",
"repository": {
"url": "https://github.com/gvergnaud/nextjs-dynamic-routes.git",
"type": "git"
},
"author": "Gabriel Vergnaud",
"license": "MIT",
"scripts": {
"build": "webpack --config ./webpack.config.js"
"build": "webpack --config webpack.config.js"
},
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-2": "^6.22.0",
"webpack": "^2.2.1"
"webpack": "^2.2.1",
"webpack-node-externals": "^1.5.4"
},
"dependencies": {
"babel-plugin-proxy": "^1.1.0",
"lodash": "^4.17.4",
"path-match": "^1.2.4",
"webpack-node-externals": "^1.5.4"
"path-match": "^1.2.4"
},
"peerDependencies": {
"next": "^2.0.0",
"react": "^15.4.2"
"next": "2.x",
"react": "15.x"
}
}
3 changes: 2 additions & 1 deletion src/dynamicNextjsRouting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pathMatch from 'path-match'
import React from 'react'
import Link from 'next/link'
import { capitalize, compose } from 'lodash/fp'
import capitalize from 'lodash/fp/capitalize'
import compose from 'lodash/fp/compose'
import { createLinkProps } from './utils/routing'
import { mapKeys, mapValues } from './utils/object'

Expand Down
5 changes: 2 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
libraryTarget: 'commonjs'
libraryTarget: 'commonjs2'
},
module: {
rules: [
Expand All @@ -19,8 +19,7 @@ module.exports = {
]
},
plugins: [
new webpack.DefinePlugin({'process.env.NODE_ENV': 'production'}),
// new webpack.optimize.UglifyJsPlugin()
new webpack.DefinePlugin({'process.env.NODE_ENV': 'production'})
],
externals: [
nodeExternals({
Expand Down
Loading

0 comments on commit 5f8a0cc

Please sign in to comment.