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

@unic/estatico-webpack

v2.0.0

Published

Uses Webpack with Babel to transpile and bundle JavaScript.

Downloads

26

Readme

@unic/estatico-webpack

Uses Webpack with Babel to transpile and bundle JavaScript.

Installation

$ npm install --save-dev @unic/estatico-webpack

Usage

It is recommended to use the tools' default config files. Specifically, creating a webpack.config.js, .babelrc.js and .browserslistrc, possibly extending the default ones. This will make the configs more portable and make them usable outside of this task.

The webpack config needs to be passed to the task, babel and browserslist are picked up automagically if present. (This would allow you to skip the default config files and just pass your webpack config to the task directly, if you prefer this approach.)

const gulp = require('gulp');

/**
 * JavaScript bundling task
 * Uses Webpack with Babel to transpile and bundle JavaScript.
 *
 * Using `--watch` (or manually setting `env` to `{ watch: true }`) starts file watcher
 */
gulp.task('js', (cb) => {
  const task = require('@unic/estatico-webpack');
  const webpackConfig = require('./webpack.config.js');

  const instance = task(defaults => ({
    webpack: webpackConfig,
    logger: defaults.logger,
  }), env);

  return instance(cb);
});

webpack.config.js extending the default one:

const defaults = require('@unic/estatico-webpack/webpack.config.js');
const env = require('minimist')(process.argv.slice(2));
const merge = require('lodash.merge');
const path = require('path');

module.exports = merge({}, defaults, {
  entry: Object.assign({
    head: './src/assets/js/head.js',
    main: './src/assets/js/main.js',
  }, (env.dev || env.ci) ? {
    dev: './src/assets/js/dev.js',
  } : {}),
  output: {
    path: path.resolve('./dist/assets/js'),
    filename: `[name]${env.dev ? '' : '.min'}.js`,
    chunkFilename: `async/[name]${env.dev ? '' : '.min'}.js`,
    publicPath: '/assets/js/',
  },
  mode: env.dev ? 'development' : 'production',
});

.babelrc.js extending the default one:

module.exports = {
  extends: '@unic/estatico-webpack/.babelrc.js',
};

.browserslistrc:

> 1%

Run task (assuming the project's package.json specifies "scripts": { "gulp": "gulp" }): $ npm run gulp js

See possible flags specified above.

API

plugin(options, env) => taskFn

Options

webpack

Type: Object Default:

{
  resolve: {
    alias: {
      handlebars: 'handlebars/runtime.js',
    },
  },
  module: {
    rules: [
      {
        test: /jquery\.js$/,
        loader: 'expose-loader?$!expose-loader?jQuery',
      },
      {
        test: /modernizrrc\.js$/,
        loader: 'expose-loader?Modernizr!webpack-modernizr-loader',
      },
      {
        test: /\.hbs$/,
        loader: 'handlebars-loader',
      },
      {
        test: /(\.js|\.jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          // See .babelrc.js
        },
      },
    ],
  },

  // Custom UglifyJS options
  optimization: {
    minimizer: [
      new UglifyJSPlugin({
        uglifyOptions: {
          mangle: {
            keep_fnames: true,
          },
        },
      }),
    ],
  },
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: 'static',
      // Path to bundle report file that will be generated in `static` mode.
      // Relative to bundles output directory.
      reportFilename: 'report.html',
      openAnalyzer: false,
      logLevel: 'warn',
    }),
    new UnminifiedWebpackPlugin(),
  ],
}

logger

Type: { info: Function, debug: Function, error: Function } Default: Instance of estatico-utils's Logger utility.

Set of logger utility functions used within the task.

License

Apache 2.0.