This is an attempt to document the internals of Crater (https://github.com/jedwards1211/crater). It's most likely out of date at any given time. I used to it to gain a better understanding of how Crater was put together.
Updated: Sept 16. 2016
src/server
- App reloads if anything changes.src/universal
- App reloads if anything changes.
Run npm start
runs babel-node scripts/start.js
.
- Runs
buildMeteor()
fromscripts/build-meteor.js
. - Builds meteor files if out of date.
- Runs
installMeteorDeps()
fromscripts/installMeteorDeps.js
. - Installs meteor npm dependencies.
- Require's
scripts/devServer.js
. - Using supervisor runs
src/index.js
and reloads the application if anything changes undersrc/server
orsrc\universal
. (These are files loaded on the server).
- Loads environment from
.env
file. - Creates an express app.
- Using the config from
webpack/webpack.config.dev.js
creates a webpack compiler. - Configures the express app with two middlewares:
webpack-dev-middleware
– Serves the output from webpack over a connect server. * Uses the webpack compiler previously created and the devServer property of the webpack config.webpack-hot-middleware
– Subscribes to changes from the server and executes them using webpack's HMR api. * Uses the same webpack compiler.- Creates a HTTP proxy to pipe all Express requests to the main app server (localhost:3000).
- Configures the Express app to listen on the webpack dev server port (localhost:4000).
- Allows proxying of websockets when needed.
- Dev server is now live on localhost:4000. This is where you point your browser.
This is the main application entry point.
- Loads the environment from the
.env
. - Load the boot.js from the meteor folder. (prod/dev dependant)
- [Dev Mode] Calls babel-register to bind require to automatically compile .jsx and .js with babel.
- Calls
Meteor.startup()
(waits until Meteor is fully started up) and then loadssrc/server/index.js
.
- Create an Express app
- If the url is for the favicon return a 404 error.
- [Production Mod] If the url is under
/static
return the static file. - For all other requests return the SSR unless it's a sockjs request (for DDP).
- Set Meteor's WebApp to use Express's rawConnectHandlers.
- App is now live on localhost:3000.
- Use Meteor.startup() to wait for Meteor to start.
- etc...
- Three entry points:
/src/client/index.js
react-hot-loader/patch
webpack-hot-middleware/client
- Plugins:
- OccurrenceOrderPlugin
- HotModuleReplacementPlugin – Enables HMR API
- NoErrorsPlugin
- DefinePlugin – Global defines
__CLIENT__
- True if on the client__PRODUCTION__
- True if in productionMeteor.isClient
- True if on the clientMeteor.isCordova
- True if using cordovaMeteor.isServer
- True if on the serverprocess.env.TARGET
-process.env.NODE_ENV
– In development is 'development'- HappyPack – Parallel transforming of modules.
- Used only for babel transforms.
- MeteorImportsPlugin – Import Meteor package like real NPM packages.
- Imports from the meteor build folder.
- Allows you to do
import {Meteor} from 'meteor/meteor;
- Module Loaders:
- JSON Loader – Configured to load all
.json
from/src
andnode_modules
. - Raw Loader – Configured to load all
.txt
files. - URL Loader – Configured to load
png|jpg|jpeg|gif|svg|woff|woff2
files. Files under 10k are embedded. - File Loader – Configured to load
eot|ttf|wav|mp3
files. - Style, CSS, PostCSS Loaders – Configured to load
.css
files under/src
. - Excludes files that are in
/src/styles/global
. - PostCSS is configured with
postcss-modules-values
to pass values between CSS files. - Style, CSS – Configured to include global
.css
files under/src/styles/global
. - HappyPack – Configured to load
.js
files with happypack.