Opinionated builder for react web projects.
This project is no longer developed, having been superseded by create-react-app.
sd-builder devsets up dev environment with auto-recompilingsd-builder buildbuilds the projectsd-builder configwrites the app configuration toapp-config.js
- The builder expects there to be an
app/main.htmlfile, which is compiled intobuild/index.html. For now the compilation consists in a simple a copy/paste.
-
The builder expects there to be an
app/main.jsxfile, which is used aswebpack's entry point. The generated bundle is written tobuild/_assets/js/app.js. -
Files are compiled by babel. It's up to the user to specify which plugins to use by installing and listing them in a
.babelrcconfig file. -
npm modules listed in
deps.json'sjsarray are separated from the main bundle and compiled intobuild/_assets/js/vendor.js. -
During
webpack's compilationNODE_PATHincludes theappdirectory. -
It's possible to
require/import.js,.jsxand.jsonfiles. -
Source maps are always generated.
- The content of the folder
app/assetswill be recursively copied intobuild/_assets.
- Files listed in
deps.json'scssarray are bundled (concat) intobuild/_assets/css/vendor.css.
- Files listed in
deps.json'sfontsarray are copied (concat) intobuild/_assets/fonts.
- the build generates a
VERSION.txtfile (written tobuild/VERSION.txt) with the following format:- if building in a git repository,
[package.json version] - [git commit sha] - otherwise,
[package.json version]
- if building in a git repository,
- when a
CHANGELOG.mdfile is present, it's copied tobuild/CHANGELOG.md
Running sd-builder config a build/app-config.js file is generated, exporting
one global variable, window.APP_CONFIG, which is a map of key-value pairs
gathered from:
- the
.envfile whenNODE_ENV=development - environment variables prefixed by
__APP_CONFIG__file whenNODE_ENV=production
You should add app-config.js script in your main.html file.
<script src="app-config.js"></script>At build time, the following environment variables can be used to customize the build:
NODE_ENV: defaults todevelopmentEXEC_ENV: defaults tobrowser
The variables are:
- passed to gulp-preprocess when
building
main.html - passed to webpack
DefinePluginwhen building js files
Example main.html build customization:
<!-- @if EXEC_ENV=='cordova' -->
<!--
This ends up in the compiled index.html only when, in the build
environment, process.env.EXEC_ENV === "cordova"
-->
<script src="cordova.js"></script>
<!-- @endif -->Example js build customization:
console.log(process.env.EXEC_ENV);
/*
* When in the build environment process.env.EXEC_ENV === "cordova", the above
* line of code will be compiled into the line `console.log("cordova");`
*/When NODE_ENV=production JS and CSS files are minified.