egg-bun

0.3.6 • Public • Published

egg-oriente-webpack

A plugin for integrating webpack to your egg.js application.

Install

$ npm i egg-bun --save

Usage

// {app_root}/config/plugin.js
exports.bun = {
  enable: true,
  package: 'egg-bun',
};

Configuration

Refer to config/config.default.js for default configurations.

Interface for bun object:

interface bun {
  /* Start compilation as soon as app is ready. */
  compileOnStart?: boolean;
  /**
   * Configuration objects.
   *  If it isn't provided, `bun` will look for `clientBaseDir/web/webpack.config.js`
   *  as webpack config.
   */
  webpackConfigs?: webpack.Configuration | [webpack.Configuration];
  /**
   * Production/development mode.
   *  In dev mode, we're using webpack-dev-middleware for all webpack configs
   *  that are meant to be served by the application server(simply put, configs that
   *  are not `targeted` as node).
   */
  isProd?: boolean;
  /* Whether to enable webpack-hot-middleware. */
  hot?: boolean;
  /* Whether to print webpack configuration stats. */
  printStats?: boolean;
  /**
   * Path to client-side source root.
   *  In case you'd like to customize your directory folder, change this to
   *  the root of client-side source code. It is important to provide this
   *  value because egg-bun uses it to ensure webpack's configuration object
   *  is position-independent.
   */
  clientBaseDir?: string;  // `${projectRoot}/web` by default.
  /**
   * Which file system webpack outputs to.
   * @see https://github.com/webpack/webpack/blob/master/lib/node/NodeOutputFileSystem.js
   */
  fileSystem?: NodeOutputFileSysten;
  /* Logger */
  logger?: Object;  // `app.logger` by default.
  /* Hooks */
  hooks?: Hooks;
}

interface Hooks {
  before?: (app: egg.Application) => void,
  beforeEach?: (compiler: webpack.Compiler) => void;
  afterEach?: (stats: webpack.Stats) => void;
  after?: () => void;
}

API

  • app.bun.build

    • returns a Promise that resolves when all compilations are done.

    Start compilation or force recompilation with current webpack configurations. Agent will be informed when either all compilations done successfully any one of the compilations fails.

    // agent.js
    module.exports = agent => {
      agent.messenger.on('doneBundled', (stats) => {
        // Perform further operations here...
      })
    
      agent.messenger.on('failedBundled', (stats) => {
    
      })
    }
  • get/set app.bun.fileSystem

    Output file system for webpack.

  • app.bun.cancel()

    Cancel all compilations.

Questions & Suggestions

No guarantee to fix issues in time, though, feel free to open an issue.

License

Wait for determination.

Package Sidebar

Install

npm i egg-bun

Weekly Downloads

0

Version

0.3.6

License

MIT

Unpacked Size

9.54 kB

Total Files

11

Last publish

Collaborators

  • aliwalker