collect artifacts for driver / plugin expose api for reading filesystem and communicating with runtime
- setup basic webpack( or other bundler )
- expose api for configure webpack
- add commands
- expose api for other user plugins api.watchFiles / api.rebuild...
- can be extended for adding new commands
- commands should be stable
- use { "scope": "pages" } to limit commands namespace
in project package.json
"scripts": { "dev": "nut pages dev", "build": "nut pages build" }
- plugin can define entries / hook artifacts / modify webpack entry / webpack dev server
- plugin can call runtime api to modify runtime code
powered by preset-pages
preset-pages -> user plugins for driver-pages
nutConfig: {
"preset": [ "preset-pages" ]
}
pages.browser.js
export default ( ctx, options ) => {
ctx.api
ctx.events
ctx.expose
ctx.emit
ctx.on
}
pages.node.js
module.exports = function ( ctx, options ) {
ctx.modifyConfig
ctx.rebuild( outputPath ) build site with different config
ctx.restart( reason ) only in dev mode
ctx.refreshBrowser
ctx.html.addScript during webpack compile
ctx.html.addMeta
ctx.html.addLink
ctx.html.addStyle
ctx.virtualModules.write()
ctx.chainWebpack
ctx.modifyWebpack
ctx.middlewares.append
ctx.middlewares.prepend
ctx.middlewares.before
ctx.middlewares.after
ctx.markdown.registerTheme
ctx.markdown.addRemarkPlugin
ctx.markdown.addRehypePlugin
// ctx.emit
// ctx.on
// ctx.expose
ctx.gatherer.watchConfig( 'layout', () => {
ctx.writeFile( )
ctx.addRoute( )
} )
ctx.gatherer.watchFile( 'pages/foo', () => {
} )
// like ctx.body
ctx.data = { foo: 'bar' }
}