Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 1.03 KB

02-customizing-webpack.md

File metadata and controls

40 lines (33 loc) · 1.03 KB

Customizing Webpack

You can extend the default webpack config using jetpack.config.js.

Here's an example of using an extra loader and a couple plugins.

// jetpack exposes it's own copy of webpack so that you can use webpack plugins
const webpack = require('jetpack/webpack')
const WorkboxWebpackPlugin = require('workbox-webpack-plugin')

module.exports = {
  webpack: (config, options) => {
    // unshift to run before other loaders, since
    // we're overriding the preconfigured svg loader
    config.module.rules[0].oneOf.unshift({
      test: /\.svg$/,
      use: ['@svgr/webpack']
    })

    // reference jetpack's webpack to use the
    // plugins that ship with webpack
    config.plugins.push(
     new webpack.NamedModulesPlugin()
    )

    // in production, add the lovely Workbox plugin
    if (options.production) {
      config.plugins.push(
        new WorkboxWebpackPlugin.GenerateSW({
          clientsClaim: true,
          exclude: [/\.map$/, /asset-manifest\.json$/]
        })
      )
    }

    return config
  }
}