├── .babelrc
├── .gitignore
├── README.md
├── package.json
├── public
├── favicon.ico
└── robots.txt
├── src
├── App.css
├── App.js
├── App.test.js
├── Home.css
├── Home.js
├── client.js
├── index.js
├── razzle.config.js
├── react.svg
└── server.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["razzle/babel"],
3 | "plugins": ["react-native-web"]
4 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | logs
2 | *.log
3 | npm-debug.log*
4 | .DS_Store
5 |
6 | coverage
7 | node_modules
8 | build
9 | .env.local
10 | .env.development.local
11 | .env.test.local
12 | .env.production.local
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](https://circleci.com/gh/jaredpalmer/razzle/tree/master)  [](https://badge.fury.io/js/razzle)
4 |
5 | Universal JavaScript applications are tough to setup. Either you buy into a framework like [Next.js](https://github.com/zeit/next.js) or [react-server](https://github.com/redfin/react-server), fork a boilerplate, or set things up yourself. Razzle aims to fill this void by abstracting all the required tooling for your universal JavaScript application into a single dependency, and then leaving the rest of the architectural decisions about frameworks, routing, and data fetching up to you.
6 |
7 | **Razzle comes with the "battery-pack included"**:
8 |
9 | - :fire: Universal Hot Module Replacement, so both the client and server update whenever you make edits. No annoying restarts necessary
10 | - Comes with your favorite ES6 JavaScript goodies (through `babel-preset-razzle`)
11 | - Comes with the same CSS setup as [create-react-app](https://github.com/facebookincubator/create-react-app)
12 | - Works with [React](https://github.com/facebook/react), [Preact](https://github.com/developit/preact), [Elm](http://elm-lang.org/), [Reason-React](https://github.com/jaredpalmer/razzle/tree/master/examples/with-reason-react), [Inferno](https://github.com/infernojs), and [Rax](https://github.com/alibaba/rax) as well as [Angular](https://github.com/angular/angular) and [Vue](https://github.com/vuejs/vue) if that's your thing
13 | - Escape hatches for customization via `.babelrc` and `razzle.config.js`
14 | - [Jest](https://github.com/facebook/jest) test runner setup with sensible defaults via `razzle test`
15 |
16 |
17 | ## Quick Start
18 |
19 | ```bash
20 | npm install -g create-razzle-app
21 |
22 | create-razzle-app my-app
23 | cd my-app
24 | npm start
25 | ```
26 |
27 | Then open http://localhost:3000/ to see your app. Your console should look like this:
28 |
29 |
30 |
31 | **That's it**. You don't need to worry about setting up multiple webpack configs or other build tools. Just start editing `src/App.js` and go!
32 |
33 | Below is a list of commands you will probably find useful.
34 |
35 | ### `npm start` or `yarn start`
36 |
37 | Runs the project in development mode.
38 | You can view your application at `http://localhost:3000`
39 |
40 | The page will reload if you make edits.
41 |
42 | ### `npm run build` or `yarn build`
43 | Builds the app for production to the build folder.
44 |
45 | The build is minified and the filenames include the hashes.
46 | Your app is ready to be deployed!
47 |
48 | ### `npm run start:prod` or `yarn start:prod`
49 | Runs the compiled app in production.
50 |
51 | You can again view your application at `http://localhost:3000`
52 |
53 | ### `npm test` or `yarn test`
54 |
55 | Runs the test watcher (Jest) in an interactive mode.
56 | By default, runs tests related to files changed since the last commit.
57 |
58 | ### `npm start -- --inspect` or `yarn start -- --inspect`
59 |
60 | To debug the node server, you can use `razzle start --inspect`. This will start the node server and enable the inspector agent. For more information, see [this](https://nodejs.org/en/docs/inspector/).
61 |
62 | ### `npm start -- --inspect-brk` or `yarn start -- --inspect-brk`
63 |
64 | To debug the node server, you can use `razzle start --inspect-brk`. This will start the node server, enable the inspector agent and Break before user code starts. For more information, see [this](https://nodejs.org/en/docs/inspector/).
65 |
66 | ---
67 |
68 |
69 |
70 | **Table of Contents**
71 |
72 | - [Customization](#customization)
73 | - [Extending Babel Config](#extending-babel-config)
74 | - [Extending Webpack](#extending-webpack)
75 | - [Environment Variables](#environment-variables)
76 | - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell)
77 | - [Windows (cmd.exe)](#windows-cmdexe)
78 | - [Linux, macOS (Bash)](#linux-macos-bash)
79 | - [Adding Environment Variables In `.env`](#adding-environment-variables-in-env)
80 | - [What other `.env` files are can be used?](#what-other-env-files-are-can-be-used)
81 | - [How Razzle works (the secret sauce)](#how-razzle-works-the-secret-sauce)
82 | - [Inspiration](#inspiration)
83 | - [Author](#author)
84 | - [Contributors](#contributors)
85 |
86 |
87 |
88 | ## CSS
89 | ### Css Modules
90 | Razzle supports both normal CSS and Css modules, you can read more about the module [here](https://github.com/css-modules/css-modules)
91 | Check `src/Home.js` for both approaches. If you import from a `module.css` file make sure to get use the default object that gets imported to access the classNames. F.e.
92 | ```
93 | import styles from './Home.module.css'
94 |
95 |
{children}
96 | ```
97 |
98 | If you would like not to use CSS modules just import you css the following way and use the classNames as before. Make sure to scope them manually:
99 |
100 | ```
101 | import './Home.css'
102 |
103 |
{children}
104 | ```
105 |
106 | ## Customization
107 |
108 | ### Extending Babel Config
109 |
110 | Razzle comes with most of ES6 stuff you need. However, if you want to add your own babel transformations, just add a `.babelrc` file to the root of your project.
111 |
112 | ```json
113 | {
114 | "presets": [
115 | "razzle/babel",
116 | "stage-0"
117 | ]
118 | }
119 | ```
120 |
121 | ### Extending Webpack
122 |
123 | You can also extend the underlying webpack config. Create a file called `razzle.config.js` in your project's root.
124 |
125 | ```js
126 | // razzle.config.js
127 |
128 | module.exports = {
129 | modify: (config, {target, dev}, webpack) => {
130 | // do something to config
131 |
132 | return config
133 | }
134 | }
135 | ```
136 |
137 | A word of advice: `razzle.config.js` is an escape hatch. However, since it's just JavaScript, you can and should publish your `modify` function to npm to make it reusable across your projects. For example, imagine you added some custom webpack loaders and published it as a package to npm as `my-razzle-modifictions`. You could then write your `razzle.config.js` like so:
138 |
139 | ```
140 | // razzle.config.js
141 | const modify = require('my-razzle-modifictions');
142 |
143 | module.exports = {
144 | modify
145 | }
146 | ```
147 |
148 | Last but not least, if you find yourself needing a more customized setup, Razzle is _very_ forkable. There is one webpack configuration factory that is 300 lines of code, and 4 scripts (`build`, `start`, `test`, and `init`). The paths setup is shamelessly taken from [create-react-app](https://github.com/facebookincubator/create-react-app), and the rest of the code related to logging.
149 |
150 | ### Environment Variables
151 |
152 | **The environment variables are embedded during the build time.** Since Razzle produces a static HTML/CSS/JS bundle and an equivalent static bundle for your server, it cannot possibly read them at runtime.
153 |
154 | - `process.env.RAZZLE_PUBLIC_DIR`: Path to the public directory.
155 | - `process.env.RAZZLE_ASSETS_MANIFEST`: Path to a file containing compiled asset outputs
156 | - `process.env.REACT_DEV_BUNDLE_PATH`: Relative path to where React will be bundled during development. Unless you are modifying the output path of your webpack config, you can safely ignore this. This path is used by `react-error-overlay` and webpack to power up the fancy runtime error iframe. For example, if you are using common chunks and an extra entry to create a vendor bundle with stuff like react, react-dom, react-router, etc. called `vendor.js`, and you've changed webpack's output to `[name].js` in development, you'd want to set this environment variable to `/static/js/vendor.js`. If you do not make this change, nothing bad will happen, you will simply not get the cool error overlay when there are runtime errors. You'll just see them in the console. Note: This does not impact production bundling.
157 | - `process.env.VERBOSE`: default is false, setting this to true will not clear the console when you make edits in development (useful for debugging).
158 | - `process.env.PORT`: default is `3000`, unless changed
159 | - `process.env.HOST`: default is `0.0.0.0`
160 | - `process.env.NODE_ENV`: `'development'` or `'production'`
161 | - `process.env.BUILD_TARGET`: either `'client'` or `'server'`
162 |
163 | You can create your own custom build-time environment variables. They must start
164 | with `RAZZLE_`. Any other variables except the ones listed above will be ignored to avoid accidentally exposing a private key on the machine that could have the same name. Changing any environment variables will require you to restart the development server if it is running.
165 |
166 | These environment variables will be defined for you on `process.env`. For example, having an environment variable named `RAZZLE_SECRET_CODE` will be exposed in your JS as `process.env.RAZZLE_SECRET_CODE`.
167 |
168 | ### Adding Temporary Environment Variables In Your Shell
169 |
170 | Defining environment variables can vary between OSes. It’s also important to know that this manner is temporary for the
171 | life of the shell session.
172 |
173 | #### Windows (cmd.exe)
174 |
175 | ```cmd
176 | set RAZZLE_SECRET_CODE=abcdef&&npm start
177 | ```
178 |
179 | (Note: the lack of whitespace is intentional.)
180 |
181 | #### Linux, macOS (Bash)
182 |
183 | ```bash
184 | RAZZLE_SECRET_CODE=abcdef npm start
185 | ```
186 |
187 | ### Adding Environment Variables In `.env`
188 |
189 | To define permanent environment variables, create a file called .env in the root of your project:
190 |
191 | ```
192 | RAZZLE_SECRET_CODE=abcdef
193 | ```
194 |
195 | #### What other `.env` files are can be used?
196 |
197 | * `.env`: Default.
198 | * `.env.local`: Local overrides. **This file is loaded for all environments except test.**
199 | * `.env.development`, `.env.test`, `.env.production`: Environment-specific settings.
200 | * `.env.development.local`, `.env.test.local`, `.env.production.local`: Local overrides of environment-specific settings.
201 |
202 | Files on the left have more priority than files on the right:
203 |
204 | * `npm start`: `.env.development.local`, `.env.development`, `.env.local`, `.env`
205 | * `npm run build`: `.env.production.local`, `.env.production`, `.env.local`, `.env`
206 | * `npm test`: `.env.test.local`, `.env.test`, `.env` (note `.env.local` is missing)
207 |
208 | These variables will act as the defaults if the machine does not explicitly set them.
209 | Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) for more details.
210 |
211 | >Note: If you are defining environment variables for development, your CI and/or hosting platform will most likely need
212 | these defined as well. Consult their documentation how to do this. For example, see the documentation for [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars).
213 |
214 | ## How Razzle works (the secret sauce)
215 |
216 | **tl;dr**: 2 configs, 2 ports, 2 webpack instances, both watching and hot reloading the same filesystem, in parallel during development and a little `webpack.output.publicPath` magic.
217 |
218 | In development mode (`razzle start`), Razzle bundles both your client and server code using two different webpack instances running with Hot Module Replacement in parallel. While your server is bundled and run on whatever port your specify in `src/index.js` (`3000` is the default), the client bundle (i.e. entry point at `src/client.js`) is served via `webpack-dev-server` on a different port (`3001` by default) with its `publicPath` explicitly set to `localhost:3001` (and not `/` like many other setups do). Then the server's html template just points to the absolute url of the client JS: `localhost:3001/static/js/client.js`. Since both webpack instances watch the same files, whenever you make edits, they hot reload at _exactly_ the same time. Best of all, because they use the same code, the same webpack loaders, and the same babel transformations, you never run into a React checksum mismatch error.
219 |
220 | ## Inspiration
221 |
222 | - [palmerhq/backpack](https://github.com/palmerhq/backpack)
223 | - [nytimes/kyt](https://github.com/nytimes/kyt)
224 | - [facebookincubator/create-react-app](https://github.com/facebookincubator/create-react-app)
225 | - [humblespark/sambell](https://github.com/humblespark/sambell)
226 | - [zeit/next.js](https://github.com/zeit/next.js)
227 |
228 |
229 | #### Author
230 | - [Jared Palmer](https://twitter.com/jaredpalmer)
231 |
232 | ---
233 | MIT License
234 |
235 | ## Contributors
236 |
237 | Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
238 |
239 |
240 | | [ Jared Palmer](http://jaredpalmer.com) [💬](#question-jaredpalmer "Answering Questions") [💻](https://github.com/jaredpalmer/razzle/commits?author=jaredpalmer "Code") [🎨](#design-jaredpalmer "Design") [📖](https://github.com/jaredpalmer/razzle/commits?author=jaredpalmer "Documentation") [💡](#example-jaredpalmer "Examples") [🤔](#ideas-jaredpalmer "Ideas, Planning, & Feedback") [👀](#review-jaredpalmer "Reviewed Pull Requests") [⚠️](https://github.com/jaredpalmer/razzle/commits?author=jaredpalmer "Tests") [🔧](#tool-jaredpalmer "Tools") | [ Jari Zwarts](https://jari.io) [💬](#question-jariz "Answering Questions") [💻](https://github.com/jaredpalmer/razzle/commits?author=jariz "Code") [🤔](#ideas-jariz "Ideas, Planning, & Feedback") [🔌](#plugin-jariz "Plugin/utility libraries") [👀](#review-jariz "Reviewed Pull Requests") | [ Dan Abramov](http://twitter.com/dan_abramov) [💻](https://github.com/jaredpalmer/razzle/commits?author=gaearon "Code") [🤔](#ideas-gaearon "Ideas, Planning, & Feedback") | [ Eric Clemmons](http://ericclemmons.github.com/) [💻](https://github.com/jaredpalmer/razzle/commits?author=ericclemmons "Code") [🤔](#ideas-ericclemmons "Ideas, Planning, & Feedback") |
241 | | :---: | :---: | :---: | :---: |
242 |
243 |
244 | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
245 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-razzle-app",
3 | "version": "2.0.0-alpha.2",
4 | "license": "MIT",
5 | "scripts": {
6 | "start": "razzle start",
7 | "build": "razzle build",
8 | "test": "razzle test --env=jsdom",
9 | "start:prod": "NODE_ENV=production node build/server.js"
10 | },
11 | "dependencies": {
12 | "@react-navigation/react-navigation-experiment-core": "^0.0.0-alpha.6",
13 | "express": "^4.16.3",
14 | "react": "^16.3.2",
15 | "react-dom": "^16.3.2",
16 | "react-native-web": "^0.6.1"
17 | },
18 | "devDependencies": {
19 | "babel-plugin-react-native-web": "^0.4.0",
20 | "razzle": "^2.0.0-alpha.12"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ericvicenti/full-stack-navigation-web/ea9694a377fb9e4d137fb7221c866b97c2bba5ca/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 |
3 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | }
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { StyleSheet, Text, View } from 'react-native';
3 | import uuid from 'uuid/v1';
4 |
5 | import { createNavigator } from '@react-navigation/react-navigation-experiment-core';
6 | const preso = [];
7 |
8 | const createFlowNavigator = (flowRoutes, config = {}) => {
9 | debugger;
10 | createNavigator;
11 | };
12 |
13 | const createTitleSlide = title => {
14 | const routeName = `TitleSlide-${uuid()}`;
15 | class TitleSlide extends React.Component {
16 | static routeName = routeName;
17 | render() {
18 | return (
19 |
20 | {title}
21 |
22 | );
23 | }
24 | }
25 | return TitleSlide;
26 | };
27 |
28 | const createMainTitleSlide = createTitleSlide;
29 |
30 | preso.push(createMainTitleSlide('Full Stack Navigation'));
31 | preso.push(createTitleSlide('Full Stack Navigation'));
32 | preso.push(createTitleSlide('Full Stack Navigation'));
33 |
34 | const App = createFlowNavigator(preso);
35 |
36 | // class App extends React.Component {
37 | // render() {
38 | // return (
39 | //
40 | // Hello, world!
41 | // Hello, world!
42 | // Hello, world!
43 | //
44 | // );
45 | // }
46 | // }
47 |
48 | // const styles = StyleSheet.create({
49 | // box: { padding: 10, borderWidth: 10, borderColor: 'blue' },
50 | // text: { fontWeight: 'bold' },
51 | // });
52 |
53 | export default App;
54 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import App from './App';
2 | import React from 'react';
3 | import ReactDOM from 'react-dom';
4 | import MemoryRouter from 'react-router-dom/MemoryRouter';
5 |
6 | describe('', () => {
7 | test('renders without exploding', () => {
8 | const div = document.createElement('div');
9 | ReactDOM.render(
10 |
11 |
12 | ,
13 | div
14 | );
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/src/Home.css:
--------------------------------------------------------------------------------
1 | .Home {
2 | text-align: center;
3 | }
4 |
5 | .Home-logo {
6 | animation: Home-logo-spin infinite 20s linear;
7 | height: 80px;
8 | }
9 |
10 | .Home-header {
11 | background-color: #222;
12 | height: 150px;
13 | padding: 20px;
14 | color: white;
15 | }
16 |
17 | .Home-intro {
18 | font-size: large;
19 | }
20 |
21 | .Home-resources {
22 | list-style: none;
23 | }
24 |
25 | .Home-resources > li {
26 | display: inline-block;
27 | padding: 1rem;
28 | }
29 |
30 | @keyframes Home-logo-spin {
31 | from {
32 | transform: rotate(0deg);
33 | }
34 | to {
35 | transform: rotate(360deg);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Home.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import logo from './react.svg';
3 | import './Home.css';
4 |
5 | class Home extends React.Component {
6 | render() {
7 | return (
8 |
9 |
10 |
11 |
Welcome to Razzle
12 |
13 |
14 | To get started, edit src/App.js or{' '}
15 | src/Home.js and save to reload.
16 |