English | 日本語
Extend Milkee's functionality with custom plugins.
Run -p (--plugin) command to set up your plugin project:
# global
milkee -p
# or local
npx milkee -pThis will:
- Initialize
package.json(if needed) - Install dependencies (
consola,coffeescript,milkee) - Create template files
- Update
package.json(main,scripts,keywords)
your-plugin/
src/
main.coffee # Your plugin source
dist/
main.js # Compiled output
.github/
workflows/
publish.yml # npm publish workflow
coffee.config.cjs
package.json
fs = require 'fs'
path = require 'path'
consola = require 'consola'
pkg = require '../package.json'
PREFIX = "[#{pkg.name}]"
# Custom logger with prefix
c = {}
for method in ['log', 'info', 'success', 'warn', 'error', 'debug', 'start', 'box']
do (method) ->
c[method] = (args...) ->
if typeof args[0] is 'string'
args[0] = "#{PREFIX} #{args[0]}"
consola[method] args...
# Main plugin function
main = (compilationResult) ->
{ config, compiledFiles, stdout, stderr } = compilationResult
c.info "Compiled #{compiledFiles.length} file(s)"
for file in compiledFiles
c.log " - #{file}"
module.exports = mainMilkee passes this object to your plugin after compilation:
| Property | Type | Description |
|---|---|---|
config |
object |
Full config from coffee.config.cjs |
compiledFiles |
string[] |
Paths to compiled .js and .js.map files |
stdout |
string |
Compiler standard output |
stderr |
string |
Compiler standard error |
const myPlugin = require('your-plugin-name');
module.exports = {
entry: 'src',
output: 'dist',
milkee: {
plugins: [
myPlugin({ customOption: 'value' }),
]
}
};# Build your plugin
npm run build
# Link for local testing
npm link
# In another project
npm link your-plugin-nameThe included workflow publishes to npm manually:
- Add
NPM_TOKENsecret to your repository - Go to Actions → Manual Publish to npm
- Click Run workflow
npm run build
npm publish --access public- Name:
milkee-plugin-xxxor@yourname/milkee-plugin-xxx - Keywords (auto-added):
milkee,coffeescript,coffee,plugin,milkee-plugin
main = (compilationResult) ->
try
# Your logic
catch error
c.error "Failed:", error.message
throw error