Skip to content

Commit

Permalink
fix(cli-plugin-service): adjust clinet side webpack config
Browse files Browse the repository at this point in the history
add 'HtmlWebpackPlugin(server side)' and 'WebpackManifestPlugin' when enable ssr
  • Loading branch information
front-end-captain committed Apr 25, 2021
1 parent 5c3890a commit ac2d342
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/@luban/cli-plugin-service/src/config/plugin.ts
Expand Up @@ -84,12 +84,20 @@ class Plugin implements ConfigPluginInstance {

webpackConfig.plugin("client-html").use(HtmlWebpackPlugin, [htmlPluginOptions]);

webpackConfig.plugin("server-html").use(HtmlWebpackPlugin, [
{
filename: "server.ejs",
template: path.resolve(__dirname, "../template/dynamic/server.template.ejs"),
},
]);
if (projectConfig.ssr) {
webpackConfig.plugin("server-html").use(HtmlWebpackPlugin, [
{
filename: "server.ejs",
template: path.resolve(__dirname, "../template/dynamic/server.template.ejs"),
},
]);

webpackConfig
.plugin("manifest")
.use(WebpackManifestPlugin, [
{ fileName: "asset-manifest.json", publicPath: projectConfig.publicPath },
]);
}

const publicDir = api.resolve("public");
if (fs.pathExistsSync(publicDir)) {
Expand All @@ -111,12 +119,6 @@ class Plugin implements ConfigPluginInstance {
]);
}

webpackConfig
.plugin("manifest")
.use(WebpackManifestPlugin, [
{ fileName: "asset-manifest.json", publicPath: projectConfig.publicPath },
]);

webpackConfig
.plugin("webpack-bar")
.use(WebpackBar, [{ name: `[Client] ${options.projectName}`, color: "#41b883" }]);
Expand Down Expand Up @@ -163,7 +165,10 @@ class Plugin implements ConfigPluginInstance {
});

api.chainAllWebpack((webpackConfig, id) => {
webpackConfig.plugin("extract-css").use(MiniCssExtractPlugin, [extractOptions]).end();
webpackConfig
.plugin("extract-css")
.use(MiniCssExtractPlugin, [extractOptions])
.end();

if (isProduction) {
if ((args as ParsedArgs<BuildCliArgs>).report) {
Expand Down

0 comments on commit ac2d342

Please sign in to comment.