build command enables us to build our decentralized application and deploy it accordingly. Similar to
embark run, it compiles our Smart Contracts, deploys them to a blockchain network that our app is connected to, processes our app’s assets and uploads them to the configured decentralized storage (e.g. IPFS).
embark build will use the
production mode to build our application.
$ embark build
Embark comes with two modes for building our application:
- development - This mode is for development purposes and produces sourcemaps as well as unoptimized client-side code. Whenever we use
embark console, this mode is used by default. Since this mode skips code optimizations, it’s also the faster mode.
- production - Unsurprisingly, this mode is used to create production artifacts of our application. It produces optimized code and therefore, takes longer to build. However, client-side code will be highly optimized, thus smaller in file size. This mode is the default for
We can specify a mode using the
--pipeline option. This is available for both,
embark run and
embark build commands:
$ embark build --pipeline development
If we’re building a Smart Contract only application, or we’re simply not interested in building the entire application and deploying it, but just want to compile our Smart Contracts, we can use the
$ embark build --contracts
Embark uses webpack to bundle and postprocess all kinds of assets of our decentralized application. This also includes things like:
- ES2015+ syntax using Babel
- Support for React & JSX
- Automatic support for older browsers via Babel’s preset-env (by default, Embark uses a browser list setting of
['last 1 version', 'not dead', '> 0.2%']
- Sourcemaps generation (when in development mode)
- Minification and tree shaking (when in production mode)
Sometimes we run into scenarios where our setup is so specific that the build process for our application needs further customization. For those cases, where Embark’s built-in build pipeline isn’t enough, it enables us to “eject” the internally used
webpack.config.js file, so we can change it to our needs and fully bypass Embark’s internal build process.
Ejecting the internally used config file is as simple as using Embark’s
eject-build-config command like this:
$ embark eject-build-config
On --eject-webpack option
In older versions of Embark, the same could be achieved using the
--eject-webpackoption. This option still works, but is now considered deprecated and will be removed in future versions of Embark.