Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --static flag to build script which allows to generate static html for specific routes #642

Merged
merged 1 commit into from
May 13, 2016

Conversation

frenzzy
Copy link
Member

@frenzzy frenzzy commented May 7, 2016

$ npm run build -- --static --release

Build folder with static html files

refs #61 #73 #156 #260 #634 #635

@Dmitry-N-Medvedev
Copy link

oh, please, accept this :)

@Dmitry-N-Medvedev
Copy link

A question: is it possible to generate static version so that index.html gets generated as well?

@frenzzy
Copy link
Member Author

frenzzy commented May 15, 2016

const routes = [
  '/',           // => build/public/index.html
  '/page',       // => build/public/page.html
  '/page/',      // => build/public/page/index.html
  '/page/name',  // => build/public/page/name.html
  '/page/name/', // => build/public/page/name/index.html
];

hackhat pushed a commit to hackhat/react-starter-kit that referenced this pull request Sep 5, 2016
…iguration has a new key named `serverSideRendering` that can be toggled between `true` and `false`. Related to: kriasoft#642, kriasoft#634
hackhat pushed a commit to hackhat/react-starter-kit that referenced this pull request Sep 5, 2016
…iguration has a new key named `serverSideRendering` that can be toggled between `true` and `false`. Related to: kriasoft#642, kriasoft#634
hackhat pushed a commit to hackhat/react-starter-kit that referenced this pull request Sep 5, 2016
…iguration has a new key named `serverSideRendering` that can be toggled between `true` and `false`. Related to: kriasoft#642, kriasoft#634
@srinivasdamam
Copy link

@frenzzy what about the routes that have params?

@frenzzy
Copy link
Member Author

frenzzy commented Oct 13, 2016

You can specify the same route multiple times with all available params manually

const routes = [
  // ...
  '/product/iphone-7',            // => build/public/product/iphone-7.html
  '/product/iphone-7/specs',      // => build/public/product/iphone-7/specs.html
  '/product/galaxy-note-7',       // => build/public/product/galaxy-note-7.html
  '/product/galaxy-note-7/specs', // => build/public/product/galaxy-note-7/specs.html
  // etc.
];

Or you can dynamically build such routes based on list of params from api or somewhere else

async function render() {
  let server;
  await new Promise(resolve => (server = runServer(resolve)));

  // add dynamic routes
  const products = await fetch(`http://${host}/api/products`).then(res => res.json());
  products.forEach(product => routes.push(
    `/product/${product.uri}`,
    `/product/${product.uri}/specs`
  ));

  await routes.reduce(/* ... */);
  server.kill('SIGTERM');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants