0.1.0 • Published 6 years ago

rollup-plugin-docker v0.1.0

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

rollup-plugin-docker

A Rollup plugin that wraps docker-preprocessor.

Install

npm install --save-dev rollup-plugin-docker

Usage

rollup-plugin-docker 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';

rollup.config.js

import docker from 'rollup-plugin-docker';
import wasmModule from 'rollup-plugin-wasm-module';

export default {
  plugins: [
    docker({
      include: ['**/*.cpp'],
      options: {
        image: 'apiaryio/emcc',
        createOptions: {
          Binds: ['/:/host'],
        },
        command: path => [
          'sh',
          '-c',
          `
            emcc \
              /host${path} \
              -g \
              -Os \
              -s WASM=1 \
              -s SIDE_MODULE=1 \
              -o target.wasm \
            ;
          `,
        ],
        paths: {
          main: '/src/target.wasm',
          emittedFiles: [
            '/src/target.wast',
          ],
          sourceMap: '/src/target.wasm.map',
        },
      },
    }),
    wasmModule({
      include: ['**/*.cpp', '**/*.rs'],
    }),
  ],
};

Options

All options are defined by and are passed directly to docker-preprocessor; check its documentation for more a in-depth explanation.