Skip to content

Instantly share code, notes, and snippets.

@c0bra
Last active November 18, 2019 17:05

Revisions

  1. c0bra revised this gist Jan 3, 2019. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions compile.js
    Original file line number Diff line number Diff line change
    @@ -17,14 +17,7 @@ function compile(filePath, name) {
    const { input, output } = generateOptions(filePath, name);

    return rollup.rollup(input)
    .then(bundle => {
    return bundle.generate(output);
    })
    .then(({ code, map }) => {
    console.log('CODE', code);

    return { code, map };
    });
    .then(bundle => bundle.generate(output));
    }

    module.exports = { compile };
  2. c0bra revised this gist Jan 3, 2019. 2 changed files with 34 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    {
    "jest": {
    "testMatch": [
    "**/test/**/*.js"
    ],
    "transform": {
    "\\.js$": "babel-jest",
    "\\.(html|svelte)$": "./test/transform"
    },
    "transformIgnorePatterns": [
    "/node_modules/(?!svelte).+\\.js$"
    ],
    "moduleFileExtensions": [
    "js",
    "json",
    "html",
    "svelte"
    ]
    }
    }
    14 changes: 14 additions & 0 deletions transform.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    const deasync = require('deasync');
    const { compile } = require('./compile');

    module.exports.process = (_s, filePath, _c, _o) => {
    let code, map;
    compile(filePath, 'App', {}).then(comp => {
    code = comp.code;
    map = comp.map;
    });

    deasync.loopWhile(() => !code && !map);

    return { code, map };
    };
  3. c0bra created this gist Jan 3, 2019.
    30 changes: 30 additions & 0 deletions compile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    const rollup = require('rollup');
    const esm = require('esm');

    const { config } = esm(module)('../rollup.config');

    function generateOptions(filePath, name) {
    return {
    input: { input: filePath, plugins: config.plugins },
    output: {
    file: `./dist/test/${name}.js`,
    format: 'cjs',
    },
    };
    }

    function compile(filePath, name) {
    const { input, output } = generateOptions(filePath, name);

    return rollup.rollup(input)
    .then(bundle => {
    return bundle.generate(output);
    })
    .then(({ code, map }) => {
    console.log('CODE', code);

    return { code, map };
    });
    }

    module.exports = { compile };