Plugin creator.
$ yarn add @start/plugin
# or
$ npm install --save-dev @start/plugin
See src/index.ts
for all the types. It's (usually) better than any words.
import plugin from '@start/plugin'
export default plugin('noop', () => () => {})
import plugin from '@start/plugin'
export default plugin('foo', ({ logPath }) => async ({ files }) => {
const { default: fooTransform } = await import('foo-lib')
return {
files: await Promise.all(
files.map(async (file) =>
const { transformedData, sourceMap } = fooTransform(file.path)
logPath(file.path)
return {
path: file.path,
data: transformedData,
map: sourceMap
}
)
)
}
})
import plugin from '@start/plugin'
export default (barOptions) =>
plugin('bar', ({ logMessage }) => async () => {
const { default: barCheck } = await import('bar-lib')
const barResult = barCheck(files, barOptions)
if (barResult.issues.length === 0) {
logMessage('¯\\_(ツ)_/¯')
}
})
- Dynamic imports – it's a good idea to "lazyload" dependencies inside of a plugin function instead of importing it on top of a file
- Plugin can return whatever "props" object or just nothing, and that output will extend an input props as an overall plugin result
files
– many plugins works withfiles
structure: it's an array of{ path, data, map }
objects, where:path
– absolute file pathdata
– file data as utf8 string, if anymap
– Source Map object, if any
logMessage
– any random message from pluginlogPath
– current file path to indicate some kind of progressreporter
– advanced prop which should be passed through if plugin operates other plugins, like sequence or watch