Skip to content

A require hook for importing asset files during runtime

Notifications You must be signed in to change notification settings

aribouius/asset-require-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asset-require-hook

A require hook for importing asset files during runtime.

Features

Allows files required by node that match a given set of extensions to be returned as either a data URI, or a custom filename. Meant to be used in conjunction with file-loader or url-loader when building universal apps.

Requirements

Using this tool requires Node.js v0.12.x or higher.

Installation

$ npm i --save asset-require-hook

Usage

Attach the require hook to the desired file extensions using the extensions parameter.

require('asset-require-hook')({
  extensions: ['jpg']
})

// const image = require('./icon.jpg');

The require hook accepts these parameters: extensions, name, publicPath and regExp.

require('asset-require-hook')({
  extensions: ['jpg'],
  name: '[hash].[ext]',
  publicPath: '/dist/',
  regExp: '\\mySpecificFilename/(.+)'
})

To enable data URI's use the limit parameter, and optionally any other parameters used by the url-loader.

require('asset-require-hook')({
  extensions: ['woff'],
  mimetype: 'application/font-woff',
  limit: 10000
})

About

A require hook for importing asset files during runtime

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •