3.0.1 • Published 1 year ago

@waldronmatt/webpack-config v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Webpack Config

A shareable webpack configuration with sensible defaults and extensible configs for assets.

Inspired by configuration practices found on survivejs.com.

Install

yarn add -D webpack webpack-merge webpack-cli @waldronmatt/webpack-config

Usage

package.json

"scripts": {
  "dev": "webpack --env development --config webpack.dev.js",
  "build": "webpack --env production --config webpack.prod.js"
}

\ webpack.dev.js

const { extendWebpackBaseConfig } = require('@waldronmatt/webpack-config');
const commonConfig = require('./webpack.common.js');

const developmentConfig = {
  // dev configs
};

module.exports = extendWebpackBaseConfig(commonConfig, developmentConfig);

\ webpack.prod.js

const { extendWebpackBaseConfig } = require('@waldronmatt/webpack-config');
const commonConfig = require('./webpack.common.js');

const productionConfig = {
  // prod configs
};

module.exports = extendWebpackBaseConfig(commonConfig, productionConfig);

\ webpack.common.js

  • Use isProduction to apply configs based on the environment.
  • Access Webpack's env variable.
  • Apply extensible base configs from @waldronmatt/webpack-config.
  • Include your own extensible configs using your own parts via const parts = require('./webpack.parts.js');.
  • Configs you set will take precedence if they overlap with @waldronmatt/webpack-config.
const { merge } = require('webpack-merge');
const { baseParts } = require('@waldronmatt/webpack-config');
const parts = require('./webpack.parts.js');

const commonConfig = (isProduction, env) => {
  // pass `isProduction` and Webpack's `env` variable into your parts file
  parts(isProduction, env);

  return merge([
    {
      entry: {
        main: './src/index.js',
      },
    },
    baseParts.loadJS({}),
    baseParts.setScriptOutputPath({}),
    baseParts.loadCSS({}),
    baseParts.setStyleOutputPath({}),
    // custom configs from your own `parts` file
    parts.loadHTMLPages({
      title: 'about',
    }),
  ]);
};

module.exports = commonConfig;

\ webpack.parts.js

Optionally set up your custom config parts to include in webpack.common.js.

const { MiniHtmlWebpackPlugin } = require('mini-html-webpack-plugin');

const parts = (isProduction, env) => {
  module.exports.loadHTMLPages = ({ title } = { title: 'MySite' }) => ({
    plugins: [
      new MiniHtmlWebpackPlugin({
        context: { title },
        publicPath: isProduction ? 'mydomain' : '/',
      }),
    ],
  });
};

module.exports = parts;

Options

You can load optional configs from this package into your own:

webpack.common.js

const { baseParts } = require('@waldronmatt/webpack-config');
  • baseParts.loadCSS({})
  • baseParts.loadSCSS({})
  • baseParts.setStyleOutputPath({})
  • baseParts.loadSourceMaps({})
  • baseParts.loadJS({})
  • baseParts.enableTypeChecking({})
  • baseParts.setScriptOutputPath({})
  • baseParts.loadImagesAsFiles({})
  • baseParts.loadImagesAsFilesOrInline({})
  • baseParts.loadFonts({})
  • baseParts.loadRawAssets({})

Note: See /src/webpack.parts.js for configuration options.

Loaders

  • esbuild-loader
  • fork-ts-checker-webpack-plugin
  • css-loader
  • postcss-loader
  • sass-loader
  • style-loader
  • mini-css-extract-plugin.loader
  • source-map-loader

Plugins

  • mini-css-extract-plugin
  • ESBuildMinifyPlugin

Included Dependencies

  • sass
  • typescript

Core Package Dependencies

  • webpack
  • webpack-merge

License

MIT

3.0.1

1 year ago

3.0.0

1 year ago

2.9.5

2 years ago

2.9.2

2 years ago

2.9.1

2 years ago

2.9.4

2 years ago

2.9.3

2 years ago

2.9.0

2 years ago

2.8.1

2 years ago

2.8.0

2 years ago

2.7.0

2 years ago

2.6.1

2 years ago

2.7.2

2 years ago

2.6.3

2 years ago

2.7.1

2 years ago

2.6.2

2 years ago

2.7.3

2 years ago

2.6.4

2 years ago

2.6.0

2 years ago

2.3.0

2 years ago

2.1.2

2 years ago

2.5.0

2 years ago

2.4.1

2 years ago

2.1.3

2 years ago

2.4.14

2 years ago

2.4.13

2 years ago

2.4.15

2 years ago

2.2.6

2 years ago

2.4.10

2 years ago

2.2.10

2 years ago

2.4.11

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

2.4.7

2 years ago

2.4.6

2 years ago

1.6.2

3 years ago

1.5.0

3 years ago

1.4.5

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago