Socket
Socket
Sign inDemoInstall

webpack

Package Overview
Dependencies
53
Maintainers
1
Versions
832
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    webpack

Packs CommonJs Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.


Version published
Weekly downloads
20M
decreased by-20.37%
Maintainers
1
Install size
11.2 MB
Created
Weekly downloads
 

Package description

What is webpack?

Webpack is a powerful module bundler for JavaScript applications. It processes applications by internally building a dependency graph which maps every module your project needs and generates one or more bundles. It is highly extensible via loaders and plugins, and it's designed to manage, transform, and bundle frontend assets like JavaScript, CSS, and images.

What are webpack's main functionalities?

Module Bundling

Webpack bundles all the JavaScript files and other assets like CSS and images into a single output file. The code sample shows a basic webpack configuration defining an entry point and the output bundle.

module.exports = {
  entry: './path/to/my/entry/file.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'my-first-webpack.bundle.js'
  }
};

Loaders

Loaders allow webpack to process different types of files and convert them into modules that can be included in your bundle. The code sample demonstrates how to use loaders to handle .txt and .css files.

module.exports = {
  module: {
    rules: [
      { test: /\.txt$/, use: 'raw-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] }
    ]
  }
};

Plugins

Plugins can be leveraged to perform a wider range of tasks like bundle optimization, asset management, and environment variable injection. The code sample shows how to use the HtmlWebpackPlugin to generate an index.html file with the bundled assets injected.

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })]
};

Development Server

Webpack provides a development server that can be used to serve your application during development. It supports live reloading. The code sample configures the webpack development server to serve files from the 'dist' directory.

module.exports = {
  devServer: {
    contentBase: './dist',
    open: true
  }
};

Code Splitting

Code splitting allows you to split your code into various bundles which can then be loaded on demand or in parallel. The code sample shows how to split the application and vendor code into separate bundles.

module.exports = {
  entry: {
    app: './src/app.js',
    vendor: './src/vendor.js'
  },
  output: {
    filename: '[name].bundle.js',
    path: __dirname + '/dist'
  }
};

Other packages similar to webpack

Readme

Source

vm-browserify

Emulate node's vm module for the browser.

example

Just write some client-side javascript:

var vm = require('vm');

$(function () {
    var res = vm.runInNewContext('a + 5', { a : 100 });
    $('#res').text(res);
});

compile it with browserify:

browserify entry.js -o bundle.js

then whip up some html:

<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <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.

browser compatability

All modern browsers are supported.

If you have a browserling account, from the testling/ directory just do:

$ ./test.sh substack@gmail.com
Enter host password for user 'substack@gmail.com':
chrome/17.0:
  vmRunInNewContext ................................. 5/5

iexplore/9.0:
  vmRunInNewContext ................................. 5/5

firefox/10.0:
  vmRunInNewContext ................................. 5/5

safari/5.1:
  vmRunInNewContext ................................. 5/5

opera/11.6:
  vmRunInNewContext ................................. 5/5

total ............................................... 25/25

In IE8 and IE7, running vm.runInNewContext() more than once can cause the browsers to hang for some reason. Otherwise they work too.

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/X11

FAQs

Last updated on 02 May 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc