Skip to main content

API Reference

AssetPack uses a config file to define what assets you want to optimise and how you want to optimise them. The config file is a JavaScript file that exports an object with the following properties:

entry

TypeDefaultRequired
stringYes

The directory where your raw assets are located.

output

TypeDefaultRequired
stringYes

The directory where you want your optimised assets to be outputted to.

ignore

TypeDefaultRequired
string[]No

An optional array of ignore patterns. Any file path matching the patterns will not be processed by AssetPack.

cache

TypeDefaultRequired
booleantrueNo

An optional boolean to enable or disable caching.

cacheLocation

TypeDefaultRequired
string'.assetpack'No

An optional string to set the location of the cache.

logLevel

TypeDefaultRequired
string'info'No

An optional string to set the log level.

pipes

TypeDefaultRequired
Plugin[]No

An array of pipes to use. For examples of pipes, see Plugins.

assetSettings

TypeDefaultRequired
AssetSetting[]No
PropertyTypeDefaultRequired
filesstringYes
settingsobjectNo
metaDataobjectNo

An optional array of asset settings. This allows you to set specific settings for individual assets.

Example

// .assetpack.js

export default {
entry: './raw-assets',
output: './public',
ignore: ['**/*.html'],
cache: true,
cacheLocation: '.assetpack',
logLevel: 'info',
pipes: [
// Pipes go here
],
assetSettings: [
{
files: ['**/*.png'],
settings: {
compress: {
jpg: true,
png: true,
// all png files will be compressed to avif format but not webp
webp: false,
avif: true,
},
},
},
],
};