Skip to content

Work in a bundle  #528

@lijingmu

Description

@lijingmu

I use webpack to create a bundle, vm2 is one dependency. webpack can work well with following config:

ignoreWarnings: [
        {
                message: /Can't resolve 'coffee-script'/,
        },
]
module: {
        parser: {
                javascript: {
                        commonjsMagicComments: true
                }
        }
}

when I run the project I encountered:

Error: ENOENT: no such file or directory, open 'xx/dist/bridge.js'

I think it is because below:

vm2/lib/vm.js
    const bridgeScript = compileScript(`${__dirname}/bridge.js`,
        `(function(global) {"use strict"; const exports = {};${fs.readFileSync(`${__dirname}/bridge.js`, 'utf8')}\nreturn exports;})`);
    const setupSandboxScript = compileScript(`${__dirname}/setup-sandbox.js`,
        `(function(global, host, bridge, data, context) { ${fs.readFileSync(`${__dirname}/setup-sandbox.js`, 'utf8')}\n})`);

vm2/lib/nodevm.js
        if (!cacheSandboxScript) {
            cacheSandboxScript = compileScript(`${__dirname}/setup-node-sandbox.js`,
                `(function (host, data) { ${fs.readFileSync(`${__dirname}/setup-node-sandbox.js`, 'utf8')}\n})`);
        }

vm2/lib/nodevm.js
     if (!cacheEventsScript) {
    const eventsSource = fs.readFileSync(`${__dirname}/events.js`, 'utf8');
    cacheEventsScript = new VMScript(`(function (fromhost) { const module = {}; module.exports={};{ ${eventsSource}
            } return module.exports;})`, {filename: 'events.js'});
     }

I have to copy these files to dist. Any suggestions or workaround?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions