npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webpack-blocks/webpack2

v0.4.0

Published

Webpack block for the webpack 2.x base configuration.

Downloads

4,363

Readme

Webpack blocks - Webpack 2 base configuration

JavaScript Style Guide NPM Version

This is the webpack2 block providing webpack 2 core functionality. Also provides all @webpack-blocks/core exports for convenience.

Usage

const HtmlWebpackPlugin = require('html-webpack-plugin')
const { addPlugins, createConfig, entryPoint, env, setOutput, sourceMaps, webpack } = require('@webpack-blocks/webpack2')

module.exports = createConfig([
  entryPoint('./src/main.js'),
  setOutput('./build/bundle.js'),
  addPlugins([
    new HtmlWebpackPlugin({
      inject: true,
      template: './index.html'
    }),
    new webpack.DefinePlugin({
      'process.env': JSON.stringify(process.env || 'development')
    })
  ]),
  env('development', [
    // will only enable source maps if `NODE_ENV === 'development'`
    sourceMaps()
  ])
])

Webpack 2 compatible blocks

There are some webpack loaders and plugins that are only compatible with webpack 2 in a certain version. Make sure you use the appropriate webpack blocks:

Exports

createConfig(configSetter: Function[]): object

Takes an array of config setters (the functions returned by invoked webpack blocks), invokes them and returns the resulting webpack config object. Already sets some generic default config, like default CSS, font and image file loaders.

createConfig.vanilla(configSetter: Function[]): object

Works just like createConfig(), but provides no default configuration whatsoever. Use it only if you want to get rid of the default loaders for some reason.

group(configSetters: Function[]): Function

Combines an array of blocks to a new joined block. Running this single block has the same effect as running all source blocks.

env(envName: string, configSetters: Function[]): Function

Applies an array of webpack blocks only if process.env.NODE_ENV matches the given envName. If no NODE_ENV is set, it will be treated as 'development'.

defineConstants(constants: object): Function

Replaces constants in your source code with a value (process.env.NODE_ENV for example) using the webpack.DefinePlugin. Pass an object containing your constant definitions: { [constantName: string]: <constantValue: any> }.

Every constant's value is JSON.stringify()-ed first, so you don't have to remember.

Special feature: Using defineConstants multiple times results in a single DefinePlugin instance configured to do all the replacements.

webpack: object

Same as require('webpack').


addPlugins(plugins: WebpackPlugin[])

Add custom plugins to the webpack configuration.

Example usage: addPlugins([ new HtmlWebpackPlugin() ])

customConfig(webpackConfigSnippet: object)

Add some custom configuration to the webpack configuration. The object you pass will be merged into the webpack configuration object.

entryPoint(entryPoint: string|string[]|object)

Adds one or multiple entry points. If the parameter is not an object the entry point(s) will be added to the default chunk named main. This way we make sure that the resulting https://webpack.github.io/docs/configuration.html#entry configuration property will always be an object.

performance(perfBudgetOptions: object)

Set a performance budget. Performance budgets are custom limits (like max bundle size) you can set to make webpack warn you or throw an error if the application exceeds those limits.

Options object:

{
  maxAssetSize: number,         // File size limit in bytes
  maxEntrypointSize: number,    // Total size (of an entry point) limit in bytes
  hints: string                 // "warning" or "error"
}

resolveAliases(aliases: object)

Sets resolve.alias. Use it to manually override module resolving.

Example usage: resolveAliases({ foo: path.resolve('./bar.js') }) will make require('foo') resolve to bar.js.

setContext(path: string)

Sets the webpack context. Not to be confused with the webpack-block's context object.

setDevTool(devtool: string)

Use it to manually set the webpack devtool property, like 'eval', 'source-map' and such.

setOutput(output: string|object)

Sets the webpack output property. Use it to tell webpack where to save the output bundle(s).

You can either pass an object that complies to the format described in the webpack docs or just pass the destination file path.

Instead of passing the destination file path you can also

  • Just pass a filename (not the complete path): The directory will default to ./build/.
  • Just pass the path to a directory (trailing /): The filename will default to bundle.js.

sourceMaps(devtool: ?string)

Just a convenience wrapper to enable sourcemaps in an easier-to-read fashion than setDevTool(). Will set webpack's devtool to 'cheap-module-source-map' if no explicit devtool is passed as parameter.

Webpack blocks

Check out the

👉 Main Documentation

Released under the terms of the MIT license.