Skip to content

🌐 api

James edited this page Apr 16, 2017 · 13 revisions
  • * required
  • ? optional
  • β›“ chainable and returns the instance
  • πŸ—― arguments - if applicable
  • πŸ“˜ example
  • πŸ”™ return value
  • configs instance of DLL with configs to export

πŸ—οΈ

dir

❗ currently, for non-static functions, this has to be the first function called. likely this will be improved with a minor refactor.

?β›“ directory to resolve paths to

πŸ—― arguments

  • ?directory
    • type: string
    • default: process.cwd()

πŸ“˜ example

configs.dir(__dirname)

config

*β›“ webpack config

πŸ—― arguments

πŸ“˜ example

const config = {
  context: './src',
  entry: { index: 'index.js' },
  output: { path: 'output', filename: '[name].js' }
}

const configs = DLL.config(config)

find

?β›“ find files in src code, use them if they haven't been edited recently

πŸ—― arguments

  • ?glob
    • type: string glob
    • default: src/**/*.+(js|jsx|ts|tsx)

πŸ“˜ example

default

configs.find()

custom

configs.find(`src/**/*.+(js|jsx|ts|tsx)`)

pkgDeps

?β›“ loads dependencies, and optionally devDependencies from package.json

πŸ—― arguments

  • ?filterFn(Array<?dependency: string>, Array<?devDependencies: string>, Array<?allDependencies: string>)
    • type: function
    • default: null

πŸ“˜ example

default package.dependencies

configs.pkgDeps()

with filter callback

configs
  .pkgDeps((deps, dev, all) => {
    if (process.env.NODE_ENV === 'production') {
      return deps
    }
    return all.filter(dep => !['fliplog'].includes(dep))
  })

lastModifiedFilter

?β›“ last modified specification filter for including files that don't change often when using .find

πŸ—― arguments

πŸ“˜ example

more on time specification obj

would filter .find to include files that were last edited at least 1 day ago

configs.lastModifiedFilter({days: 1})

debug

?β›“ enables or disables debugging logs

uses fliplog

πŸ—― arguments

  • ?should
    • type: boolean

πŸ“˜ example

configs.debug(true)

toConfig

* returns an array of webpack configs, your application config(s), alongside dll config(s) when needed

πŸ”™ returns

Array<Object> webpack configs

πŸ“˜ example

module.exports = configs.toConfig()

staleTime

? after a certain number of time since the last DLL build, build it again to keep it fresh

πŸ—― arguments

πŸ“˜ example

more on time specification obj

configs.everyX(100)

everyX

? every X number of builds, rebuild the dll, clears the cache to keep it light

πŸ—― arguments

  • number
    • type: number
    • default: 33

πŸ“˜ example

configs.everyX(100)

og

when needed (e.g. testing time difference), for ease-of-use, this will return the original (og) config in .toConfig() regardless of the other settings

πŸ—― arguments

  • number
    • type: number
    • default: 33

πŸ“˜ example

configs.everyX(100)

cacheBustingFiles

? an array of absolute file paths that bust the cache when changed using flipcache

πŸ—― arguments

  • files
    • type: array
    • default: [require.main.filename, resolve(dir, package.json)]

πŸ“˜ example

const {resolve} = require('path')
const res = rel => resolve(__dirname, rel)

const files = [res('./src/vendor.js'), res('./.babelrc')]
configs.cacheBustingFiles(files)

auto (static)

?β›“ use all defaults, configure config & dir, call other required functions automatically

πŸ—― arguments

  • config
    • type: object
  • dir

πŸ”™ returns

Array<Object> webpack configs

πŸ“˜ example

const configs = DLL.auto(config, __dirname)

is the same as using the default values by calling each method manually

const auto = new DLL()
const configs = auto
  .dir(__dirname)
  .config(config)
  .find()
  .pkgDeps()
  .toConfig()

configs (static)

for an array of configs

πŸ—― arguments

  • configs
    • type: array
  • cb called for each config, same usage as the api
    • type: function

πŸ”™ returns

Array<Object> webpack configs (flattens the return array configs, since each config becomes an array itself to contain dll config when needed)


context

?β›“ context property for DLLPlugin

πŸ—― arguments

  • type: string path?? (docs do not seem to cover this)

Webpack DLLPlugin source Webpack DllReferencePlugin source

shouldBeUsed

?β›“ override whether to use dll plugin or not, force using or not

πŸ—― arguments

  • type: boolean

πŸ“˜ example

const configs = dll.dir(__dirname).config(config).shouldBeUsed(true).toConfig()

clearCache

?β›“ delete the cache files

πŸ“˜ example

dll.clearCache()

time-specifications

check that the difference is equal or greater than specification.

(use only 1 property, all are integers)

  • longhand: {seconds, hours, minutes, days, years}
  • shorthand: {s, h, m, d, y}
// true: was >= 60 seconds ago
tillNowSatisfies(Date.now() - 60000, {seconds: 60})