0.1.0 • Published 6 years ago
docker-loader v0.1.0
docker-loader
A Webpack loader that wraps
docker-preprocessor
.
Install
npm install --save-dev docker-loader
Usage
docker-loader
is for tasks that require lots of setup or configuration of the
host machine. A good example is compiling C++ to WebAssembly (wasm), which
requires Emscripten to be compiled, configured, and installed.
This can also be used for multiple times within a configuration for different file types, allowing for easy seperation of concerns via Docker containers.
file.js
import wasmModule from 'file.cpp';
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.cpp?$/,
use: [
{
loader: 'wasm-module-loader',
},
{
loader: 'docker-loader',
options: {
image: 'apiaryio/emcc',
createOptions: {
Binds: ['/:/host'],
},
command: path => [
'sh',
'-c',
`
emcc \
/host${path} \
-g \
-Os \
-s WASM=1 \
-s SIDE_MODULE=1 \
-s ONLY_MY_CODE=1 \
-o targetCpp.wasm \
;
`,
],
paths: {
main: '/src/targetCpp.wasm',
emittedFiles: [
'/src/targetCpp.wast',
],
sourceMap: '/src/targetCpp.wasm.map',
},
},
},
],
},
],
},
};
Options
All options are defined by and are passed directly to
docker-preprocessor
; check its documentation for more a
in-depth explanation.