Skip to content

Commit

Permalink
feat: add htmlWebpackPlugin in development
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed May 30, 2019
1 parent bd06a69 commit 88fcfa8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/generators/init-generator.ts
Expand Up @@ -12,6 +12,7 @@ import entryQuestions from "./utils/entry";
import langQuestionHandler, { LangType } from "./utils/languageSupport";
import styleQuestionHandler, { Loader, StylingType } from "./utils/styleSupport";
import tooltip from "./utils/tooltip";
import { generatePluginName } from "./utils/plugins";

/**
*
Expand Down Expand Up @@ -224,6 +225,19 @@ export default class InitGenerator extends Generator {
);
}
}
if(!this.isProd) {
this.dependencies.push("html-webpack-plugin");
const htmlWebpackDependency: string = "html-webpack-plugin";
const htmlwebpackPlugin: string = generatePluginName(htmlWebpackDependency);
(this.configuration.config.topScope as string[]).push(
`const ${htmlwebpackPlugin} = require('${htmlWebpackDependency}')`,
"\n",
tooltip.html(),
);
(this.configuration.config.webpackOptions.plugins as string[]).push(
`new ${htmlwebpackPlugin}()`,
);
}
done();
}

Expand Down
11 changes: 11 additions & 0 deletions packages/generators/utils/tooltip.ts
Expand Up @@ -57,6 +57,17 @@ export default {
*
* https://github.com/webpack-contrib/terser-webpack-plugin
*
*/`;
},

html: (): string => {
return `/*
* We've enabled HtmlWebpackPlugin for you! This generates a html
* page for you when you compile webpack, which will make you start
* developing and prototyping faster.
*
* https://github.com/jantimon/html-webpack-plugin
*
*/`;
}
};
6 changes: 3 additions & 3 deletions packages/generators/utils/webpackConfig.ts
Expand Up @@ -4,15 +4,15 @@ export function getDefaultOptimization(isProd: boolean): WebpackOptions["optimiz
let optimizationOptions;
if (isProd) {
optimizationOptions = {
minimizer: [
"new TerserPlugin()",
],
splitChunks: {
chunks: "'all'",
},
};
} else {
optimizationOptions = {
minimizer: [
"new TerserPlugin()",
],
splitChunks: {
cacheGroups: {
vendors: {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/run-prettier.ts
Expand Up @@ -19,7 +19,7 @@ export default function runPrettier(outputPath: string, source: string, cb?: Fun
try {
prettySource = prettier.format(source, {
filepath: outputPath,
parser: "babylon",
parser: "babel",
singleQuote: true,
tabWidth: 1,
useTabs: true,
Expand Down

0 comments on commit 88fcfa8

Please sign in to comment.