https://github.com/mfellner/webpack-sandboxed
Webpack in a sandbox.
https://github.com/mfellner/webpack-sandboxed
webpack
Last synced: about 1 year ago
JSON representation
Webpack in a sandbox.
- Host: GitHub
- URL: https://github.com/mfellner/webpack-sandboxed
- Owner: mfellner
- License: mit
- Created: 2016-09-15T21:13:35.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-09T15:41:32.000Z (over 8 years ago)
- Last Synced: 2024-04-25T00:02:47.238Z (about 2 years ago)
- Topics: webpack
- Language: TypeScript
- Homepage: https://runkit.com/mfellner/webpack-sandboxed
- Size: 230 KB
- Stars: 7
- Watchers: 0
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# webpack-sandboxed [](https://badge.fury.io/js/webpack-sandboxed) [](https://travis-ci.org/mfellner/webpack-sandboxed) [](https://coveralls.io/github/mfellner/webpack-sandboxed?branch=master) [](https://codeclimate.com/github/mfellner/webpack-sandboxed)
Webpack in a sandbox. Run webpack on a in-memory file system, reading from a source string and outputting results as strings again. This is useful when using webpack for compiling bundles on the fly, e.g. on a web server.
---
### Usage
```js
import webpackSandboxed from 'webpack-sandboxed';
const options = {
config: { /* webpack configuration */ },
packages: [ /* names of modules to load in the sandbox */ ],
includes: [ /* local file paths to load in the sandbox */ ],
baseDir: 'base directory to resolve modules'
};
const sandbox = await webpackSandboxed(options);
const [bundle, stats] = sandbox.run("exports = {foo: 'bar'};");
```
### API
**`webpackSandboxed(options: Options): WebpackRunner`**
Create a new instance of `WebpackRunner`.
**`Options`**
Options to configure webpack and webpack sandboxed.
* `config?: webpack.Configuration` – [webpack configuration](https://webpack.js.org/configuration)
* `packages?: string[]` – A list of node_modules to load into the virtual file system.
* `includes?: string[]` – A list of directories to add to the virtual file system.
* `basedir?: string` – The base directory to resolve modules from. Defaults to the parent directory of the webpack-sandboxed installation.
**`WebpackRunner`**
Webpack sandboxed instance.
* `run(source: string | Buffer): Promise<[WebpackBundle, webpack.Stats]>` – Run webpack asynchronously (delegating to [`WebpackCompiler.run`](https://webpack.js.org/api/node/#run)).
**`WebpackBundle`**
Result of a webpack sandboxed run.
* `[key: string]: Buffer` – The set of files generated by webpack (bundles and assets).
### Example
Please view the [example](example) directory for a complete example of how to use webpack sandboxed.
### References
This project was inspired by others:
* https://github.com/webpack/webpack/issues/1562
* https://github.com/christianalfoni/webpack-bin/issues/106
* https://github.com/christianalfoni/webpack-bin