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

@softwareventures/webpack-config

v6.0.0

Published

Standard webpack configuration for Software Ventures Limited

Downloads

715

Readme

webpack-config

Simplified and opinionated webpack configuration.

This package implements a standard webpack configuration preferred by Software Ventures Limited, but can also be used by others.

Why?

Configuring webpack from scratch is time-consuming and complicated. This package provides a standard webpack configuration that is suitable for most projects.

Upgrading from v3 or earlier

See Upgrade Guide.

Setup

Add a dependency on this package, webpack, and webpack-dev-server, for example using npm or yarn:

$ npm install --save-dev @softwareventures/webpack-config webpack webpack-cli webpack-dev-server
$ yarn add --dev @softwareventures/webpack-config webpack webpack-cli webpack-dev-server

Create a webpack.config.cjs file at the root of your project with the following contents:

const config = require("@softwareventures/webpack-config");

module.exports = config({
    title: "Name of your app"
});

webpack-config exports a single function, config. Options may be passed to config as an object or as a function that returns an object.

The config function itself returns a webpack configuration, which should be exported by webpack.config.cjs.

We also recommend that you add a build and start script to package.json:

{
    "scripts": {
        "build": "webpack --env production",
        "start": "webpack-dev-server --open"
    }
}

See Building and Dev Server for more on these scripts.

TypeScript Support

To enable TypeScript, first add dev dependencies on ts-loader and typescript, and a dependency on tslib:

npm install --save-dev ts-loader typescript
npm install --save tslib

or

yarn add --dev ts-loader typescript
yarn add tslib

Then create a tsconfig.json file at the root of your project with the following contents:

{
    "extends": "@softwareventures/webpack-config/tsconfig/general",
    "compilerOptions": {
        "types": [
            "webpack-env",
            "@softwareventures/webpack-config/webpack-config-runtime"
        ]
    }
}

webpack-config provides several preset TypeScript configurations for different purposes, which can be used in place of the above:

  • @softwareventures/webpack-config/tsconfig/general: General purpose configuration suitable for most projects.
  • @softwareventures/webpack-config/tsconfig/general-commonjs: Same as general, but modules are compiled to CommonJS module format instead of ESM. Useful for older projects that are not ready to transition to ESM. Not recommended for new projects.
  • @softwareventures/webpack-config/tconfig/preact: Configuration suitable for projects using JSX with Preact.
  • @softwareventures/webpack-config/tconfig/preact-commonjs: Same as preact, but modules are compiled to CommonJS module format instead of ESM. Useful for older projects that are not ready to transition to ESM. Not recommended for new projects.
  • @softwareventures/webpack-config/tsconfig/react: Configuration suitable for projects using JSX with React.
  • @softwareventures/webpack-config/tsconfig/react-commonjs Same as react, but modules are compiled to CommonJS module format instead of ESM. Useful for older projects that are not ready to transition to ESM. Not recommended for new projects.

Any of these presets can be used as a base with project-specific overrides. Any options set in tsconfig.json will override those set by the preset. See tsconfig.json in the TypeScript Handbook for more information on configuring TypeScript.

Building

We recommend that you set up a script in package.json to build your project, as follows:

{
    "scripts": {
        "build": "webpack --env production"
    }
}

You can then run the build script using npm or yarn:

npm run build
yarn build

Build output goes in dist by default.

Dev Server

We recommend that you set up a script in package.json to run the dev server, as follows:

{
    "scripts": {
        "start": "webpack serve --open"
    }
}

You can then run the dev server using npm or yarn:

npm start
yarn start

See Also