Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Last active September 27, 2018 17:17
Show Gist options
  • Select an option

  • Save tbranyen/8648019e37e7d65a9100b5c5907669c2 to your computer and use it in GitHub Desktop.

Select an option

Save tbranyen/8648019e37e7d65a9100b5c5907669c2 to your computer and use it in GitHub Desktop.

Revisions

  1. tbranyen revised this gist Sep 27, 2018. 1 changed file with 0 additions and 13 deletions.
    13 changes: 0 additions & 13 deletions cjs-treeshake.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,3 @@
    const { throws, equal } = require('assert');
    const { register, unregister, webapp } = require('../lib');
    const { format } = require('./_utils');

    const defaults = {
    config: null,
    disableCache: true,
    disableRegistry: true,
    debug: true,
    };

    const inputType = 'script';

    it('will treekshake a static named import', async () => {
    const input = register('./a')`
    const { a } = require('./b');
  2. tbranyen revised this gist Sep 27, 2018. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions cjs-treeshake.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,16 @@
    const { throws, equal } = require('assert');
    const { register, unregister, webapp } = require('../lib');
    const { format } = require('./_utils');

    const defaults = {
    config: null,
    disableCache: true,
    disableRegistry: true,
    debug: true,
    };

    const inputType = 'script';

    it('will treekshake a static named import', async () => {
    const input = register('./a')`
    const { a } = require('./b');
  3. tbranyen created this gist Sep 27, 2018.
    34 changes: 34 additions & 0 deletions cjs-treeshake.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    it('will treekshake a static named import', async () => {
    const input = register('./a')`
    const { a } = require('./b');
    console.log(a);
    `;

    register('./b')`
    function b() {}
    exports.a = 'hello world';
    exports.b = b;
    `;

    const { source } = await webapp({
    ...defaults,
    input,
    inputType,
    });

    equal(source.code, format`
    var module = {
    exports: {}
    };
    var exports = module.exports;
    exports.a = 'hello world';
    const a = exports.a;
    var a_module_1 = {
    exports: {}
    };
    var a_exports_1 = a_module_1.exports;
    console.log(a);
    this.webapp = a_module_1.exports;
    `);
    });