Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Collection of useful utilities for razzle.config.js

Notifications You must be signed in to change notification settings

d4rky-pl/razzle-config-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

razzle-config-utils

razzle-config-utils is a set of utilities for razzle.config.js

If there's a snippet of code that you keep reusing in your own razzle config, consider sending a pull request!

TOC

API

Plugins

getPluginIndex

Retrieves plugin's index in webpack configuration or returns null

Parameters

  • config Object webpack configuration
  • name string Plugin name

Returns (number | null)

isPluginLoaded

Checks if plugin is loaded

Parameters

  • config Object webpack configuration
  • name string Plugin name

Returns boolean

modifyPlugin

Modifies webpack plugin in place.

Parameters

Examples

modifyPlugin(appConfig, 'StartServerPlugin', (plugin) => {
  plugin.options.nodeArgs = [Object']plugin - Plugin  
})
  • Throws Error an exception if it cannot find requested plugin

Returns any result of the callback

replacePlugin

Replaces webpack plugin. If the plugin cannot be found, it's ignored.

Parameters

  • config Object webpack configuration
  • name string Plugin name
  • plugin Object Plugin instance (ex. new MinifyPlugin())

Examples

replacePlugin(appConfig, 'UglifyJsPlugin', new MinifyPlugin())

Returns any plugin

Callbacks

modifyPluginFn

Callback that will be invoked with found plugin.

Type: Function

Parameters

Rules

getRuleIndexByTest

Retrieves rule's index in webpack configuration by test property

Parameters

  • config Object webpack configuration
  • test string exact value of test property

Returns (number | null)

getRuleIndexByLoader

Retrieves rule's index in webpack configuration by loader. Returns first found result.

Parameters

  • config Object webpack configuration
  • loaderName
  • loader string loader name

Returns (number | null)

modifyRule

Modifies webpack rule in place. You can pass either test property (ex. { test: /\.css$/ }) or loader (ex. { loader: 'css-loader' })` to the second argument.

Parameters

Examples

modifyRule(appConfig, { test: /\.css$/ }, (rule) => {
  rule.test = /\.s?css/
  rule.use.push({ loader: 'scss-loader' })
})
  • Throws Error an exception if it cannot find requested rule

Returns any result of the callback

replaceRule

Replaces webpack rule. You can pass either test property (ex. { test: /\.css/ }) or loader (ex. { loader: 'css-loader' })` to the second argument. If the rule cannot be found, it's ignored.

Parameters

  • config Object webpack configuration
  • $1 Object
    • $1.test
    • $1.loader
  • rule

Examples

replaceRule(appConfig, { test: /\.css$/ }, {
  test: /\.s?css/,
  use: [
    // ... etc
  ]
})

Returns any rule

ignoreFileExtension

Adds file extension to the list of extensions ignored by file-loader This is useful if you're adding support for something that Razzle does not support yet (SASS/Less, Handlebars, you name it)

Parameters

  • config Object webpack configuration
  • extension RegExp file extension

Examples

ignoreFileExtension(appConfig, /\.hbs$/)

Returns any rule

Callbacks

modifyRuleFn

Callback that will be invoked with found rule.

Type: Function

Parameters

About

Collection of useful utilities for razzle.config.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published