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

wright-webpack-config

v1.1.0

Published

A webpack config for internal use.

Downloads

5

Readme

wright-webpack-config

A Webpack config for internal use (but it's CC0, so you can use it too if you want!), that supports every feature in every published ECMAScript version (even those that use polyfills), and produces separate bundles for evergreen browsers and Internet Explorer. This lets us exclude polyfills and Babel transforms for features that evergreen browsers support, reducing file size.

It also includes support for the following:

  • React/JSX
  • TypeScript/TSX
  • Imports of CSS files
  • CSS Modules (with the recommended .module.css or alternative .icss file extensions)
  • Bundle Tracker (important for Django integration!)
  • CleanWebpackPlugin (helps avoid filling up your disk and/or crashing Webpack due to too many files.)

Usage

Install wright-webpack-config. You'll also need to install webpack, core-js, and (if you're using it) typescript yourself.

Then, in your webpack.config.js:

const config = require("wright-webpack-config").default
const path = require("path")

module.exports = config({
  inDir: path.resolve(__dirname, "js"),
  outDir: path.resolve(__dirname, "myproject", "static", "build"),
})

If you're using TypeScript, you'll also want to add the following to your tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "es2015"
  }
}

This stops TypeScript from producing ES3 output unconditionally, instead letting babel-preset-env produce the appropriate code for the appropriate browsers. (If you're using Relay, it also prevents TypeScript from munging the names of imported identifiers in a way that prevents Relay from working.)

Then, run webpack --mode development, or webpack --mode production. Don't run webpack -d or webpack -p, they are not shorthand for the above!

Parameters

  • inDir: Required. Root directory of your frontend code.
  • outDir: Required. Directory to output code to.
  • publicPath: Path that Webpack output will be available from on the server. Defaults to /static/build/.
  • transformConfig: Function that takes the generated config and potentially makes changes to it.

Example usage with Django

Install django-webpack-loader, then edit your settings.py:

 INSTALLED_APPS = (
     # ...
+    'webpack_loader',
 )

 # ...

+WEBPACK_LOADER = {
+    'evergreen': {
+        'BUNDLE_DIR_NAME': 'build/',
+        'STATS_FILE': os.path.join(STATIC_DIR, 'build',
+                                   '__webpack.evergreen.json'),
+    },
+    'iexplore': {
+        'BUNDLE_DIR_NAME': 'build/',
+        'STATS_FILE': os.path.join(STATIC_DIR, 'build',
+                                   '__webpack.iexplore.json'),
+    },
+}

Then, in your templates, add the following:

{% load webpack_loader %}
{# ... #}
{% if 'Trident/' in request.META.HTTP_USER_AGENT %}
    {% render_bundle 'main' config='iexplore' %}
{% else %}
    {% render_bundle 'main' config='evergreen' %}
{% endif %}

License