$ cnpm install egg-webpack
Webpack dev server plugin for egg, support read file in memory and hot reload. More Detail
$ npm i egg-webpack --save
// {app_root}/config/plugin.js
exports.webpack = {
enable: true,
package: 'egg-webpack',
};
support native webpack config and easywebpack webpack config
// {app_root}/config/config.default.js
exports.webpack = {
// port: 9000,
// webpackConfigList: [],
};
config.webpack = {
proxy: {
host: 'http://127.0.0.1:9000', // target host that matched path will be proxy to
match: /^\/public\//, // proxy url path pattern.
},
}
${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')]
};
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()
};
${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')
};
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.
app.webpack.fileSystem
to app, you can customize the webpack memory file read logic// read webpack browser build mode memory file content
app.webpack.fileSystem.readWebpackMemoryFile(filePath).then(fileContent =>{
})
'usestrict';
const path = require('path');
const egg = require('egg');
const vueServerRenderer = require('vue-server-renderer');
module.exports = class IndexController extends egg.Controller {
async index(ctx) {
const { app } = ctx;
const filepath = path.join(app.config.view.root[0], 'app.js');
// server render mode, the webpack config target:node
const strJSBundle = await app.webpack.fileSystem.readWebpackMemoryFile(filepath);
ctx.body = await vueServerRenderer.createBundleRenderer(strJSBundle).renderToString({});
}
};
see lib/server.js for more detail.
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.
Please open an issue here.
Copyright 2013 - present © cnpmjs.org