5.0.1 • Published 3 years ago

egg-webpack v5.0.1

Weekly downloads
320
License
MIT
Repository
github
Last release
3 years ago

egg-webpack

NPM version build status Test coverage David deps Known Vulnerabilities npm download

webpack dev server plugin for egg, support read file in memory and hot reload. More Detail

  • support webpack native configuration by webpack.webpackConfigList
  • when no config webpack.webpackConfigList, egg-webpack will dynamic create webpack config by webpack.config.js(easywebpack), and start multiple process build.

Install

$ npm i egg-webpack --save

Usage

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

Configuration

support native webpack config and easywebpack webpack config

// {app_root}/config/config.default.js
exports.webpack = {
  // port: 9000,  
  // proxy: true,
  // webpackConfigList: [],
};
  • port: {Number}, default 9000. webpack dev server port, default 9000, when hava multile webpack config, the port incremented。
  • browser: {Boolean | String} if it is boolean type, whether to open the browser automatically, defualt true; if it is string, That is url address, will automatically open the browser's url address。
  • proxy: {Boolean}, default true. webpack compiled in a separate service inside, you can use project domain and port access static resources。
  • webpackConfigList: {Array}, optional, default []. native webpack config.
  • webpackConfigFile: {String}, optional, you must set when you easywebpack config file is not in the project root directory。

webpack native configuration

  • if you write one native webpack config ${app_root}/build/webpack.config.js, you can use like this:
// {app_root}/config/config.default.js
exports.webpack = {
  webpackConfigList: [require('../build/webpack.config.js')]
};
  • if you use easywebpack solution, you can use like this:

default read webpack.config.js file under the project root directory.

const EasyWebpack = require('easywebpack-vue');
// {app_root}/config/config.default.js
exports.webpack = {
  webpackConfigList: EasyWebpack.getWebpackConfig()
};
  • if you use easywebpack solution, the easywebpack config file in ${app_root}/build/webpack.config.js, you can use like this:
const EasyWebpack = require('easywebpack-vue');
// {app_root}/config/config.default.js
exports.webpack = {
  webpackConfigList: EasyWebpack.getWebpackConfig('build/webpack.config.js')
};

easywebpack configuration

The default read webpack.config.js file under the project root directory.

// {app_root}/config/config.default.js
exports.webpack = {
  webpackConfigFile: 'build/webpack.config.js', // easywebpack config file path
};

see config/config.default.js for more detail.

Customise

  • mount app.webpack.fileSystem to app, you can customize the file read logic
// read webpack browser build mode memory file content
app.webpack.fileSystem.readWebpackMemoryFile(filePath).then(fileContent =>{

})

see lib/server.js for more detail.

  • monitor webpack build state
app.messenger.on(app.webpack.Constant.EVENT_WEBPACK_BUILD_STATE, data => {
  if (data.state) {
    const filepath = path.join(app.baseDir, 'config/manifest.json');
    const promise = app.webpack.fileSystem.readWebpackMemoryFile(filepath);
    promise.then(content => {
      fs.writeFileSync(filepath, content, 'utf8');
    });
  }
});

see lib/constant.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

5.0.1

3 years ago

4.5.5

3 years ago

5.0.0

4 years ago

5.0.0-beta.1

4 years ago

4.5.4

4 years ago

4.5.3

4 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.9-next

5 years ago

4.4.9

5 years ago

4.4.8

5 years ago

4.4.7

6 years ago

4.4.6

6 years ago

4.4.5

6 years ago

4.4.4

6 years ago

4.4.3

6 years ago

4.4.2

6 years ago

4.4.1

6 years ago

4.4.0

6 years ago

4.4.0-rc.4

6 years ago

4.4.0-rc.3

6 years ago

4.4.0-rc.2

6 years ago

4.4.0-rc.1

6 years ago

4.3.1

6 years ago

4.3.0

6 years ago

4.2.0-rc.1

6 years ago

4.1.2

6 years ago

3.3.6

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

3.3.5

6 years ago

3.3.4

6 years ago

4.0.5

6 years ago

3.3.3

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

4.0.0-rc.2

6 years ago

4.0.0-rc.1

6 years ago

4.0.0-beta.1

6 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.8

6 years ago

3.2.7

6 years ago

3.2.6

6 years ago

3.2.5

6 years ago

3.2.4

6 years ago

3.2.3

6 years ago

3.2.2

6 years ago

3.2.0

6 years ago

3.1.0-beta.2

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

2.2.5

7 years ago

3.0.0

7 years ago

2.2.4

7 years ago

2.2.3

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago