1.4.0 • Published 8 years ago
@drupe/server v1.4.0
Server Component
Bundle server-side code using webpack.
- Complies with the webpack compiler standard.
- Supports watching for changes.
- Can create a development server process.
- Enables server-side hot module replacement for development.
- Does not bundle external modules.
Installation
npm i @drupe/serverUsage
const Server = require('@drupe/server')
// Factory configuration:
components: {
server: new Server({
output: 'server',
entry: './server.js',
useRestArgs: false,
defineContext: undefined
})
}- output
<string>- Optional. The output path (relative tofactory.output). - entry
<string> | <array>- The entry. This can be a string or an array of entry points. - useRestArgs
<boolean>- Can be used to provide provide command line arguments for the development server process. - defineContext
<string>- This can be used for defining the context path for this component.
Development Server
To enable the development server, pass the --run option to the cli. The server will be started automatically after the build is complete.
node factory.js --runArguments
If you want to pass arguments to the development server, you have to set the useRestArgs configuration option to true.
node factory.js --run -- --example 'Hello World!'
# Arguments passed to the server process: --example 'Hello World!'Module paths
As all code is bundled using webpack, __dirname and __filename are relative to the context directory. As the current working directory of the server might change, you need to access the path of this context directory to resolve module relative paths.
// Server configuration:
defineContext: 'process.env.CONTEXT'
// Server code:
// Real filename of the current module:
path.resolve(process.env.CONTEXT, __filename)
// Real dirname of the current module:
path.resolve(process.env.CONTEXT, __dirname)Component API
In addition to the webpack compiler standard, the following component api is available:
hook: clear(task)
This hook is called when the output directory has been cleared.