admin_vue/11-前端模块化开发Webpack(Node.js基础)/04-webpack_Loader使用/node_modules/vm-browserify
3056762376@qq.com 3aeda6d214 changes 2022-11-20 18:09:32 +08:00
..
.github changes 2022-11-20 18:09:32 +08:00
example/run changes 2022-11-20 18:09:32 +08:00
test changes 2022-11-20 18:09:32 +08:00
.travis.yml changes 2022-11-20 18:09:32 +08:00
CHANGELOG.md changes 2022-11-20 18:09:32 +08:00
LICENSE changes 2022-11-20 18:09:32 +08:00
index.js changes 2022-11-20 18:09:32 +08:00
package.json changes 2022-11-20 18:09:32 +08:00
readme.markdown changes 2022-11-20 18:09:32 +08:00
security.md changes 2022-11-20 18:09:32 +08:00

readme.markdown

vm-browserify

emulate node's vm module for the browser

Build Status

example

Just write some client-side javascript:

var vm = require('vm');

window.addEventListener('load', function () {
    var res = vm.runInNewContext('a + 5', { a : 100 });
    document.querySelector('#res').textContent = res;
});

compile it with browserify:

browserify entry.js -o bundle.js

then whip up some html:

<html>
  <head>
    <script src="/bundle.js"></script>
  </head>
  <body>
    result = <span id="res"></span>
  </body>
</html>

and when you load the page you should see:

result = 105

methods

vm.runInNewContext(code, context={})

Evaluate some code in a new iframe with a context.

Contexts are like wrapping your code in a with() except slightly less terrible because the code is sandboxed into a new iframe.

install

This module is depended upon by browserify, so you should just be able to require('vm') and it will just work. However if you want to use this module directly you can install it with npm:

npm install vm-browserify

license

MIT