From 88fcfa8222f32593b3d8adae46a24b545f7d1c78 Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Thu, 30 May 2019 18:23:17 +0200 Subject: [PATCH] feat: add htmlWebpackPlugin in development --- packages/generators/init-generator.ts | 14 ++++++++++++++ packages/generators/utils/tooltip.ts | 11 +++++++++++ packages/generators/utils/webpackConfig.ts | 6 +++--- packages/utils/run-prettier.ts | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/generators/init-generator.ts b/packages/generators/init-generator.ts index a2733828d8b..8997c3f66e5 100644 --- a/packages/generators/init-generator.ts +++ b/packages/generators/init-generator.ts @@ -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"; /** * @@ -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(); } diff --git a/packages/generators/utils/tooltip.ts b/packages/generators/utils/tooltip.ts index cd9dba4e7ec..c58c7fba922 100644 --- a/packages/generators/utils/tooltip.ts +++ b/packages/generators/utils/tooltip.ts @@ -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 + * */`; } }; diff --git a/packages/generators/utils/webpackConfig.ts b/packages/generators/utils/webpackConfig.ts index 3ae9ce88d5a..b67d3c6d0c5 100644 --- a/packages/generators/utils/webpackConfig.ts +++ b/packages/generators/utils/webpackConfig.ts @@ -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: { diff --git a/packages/utils/run-prettier.ts b/packages/utils/run-prettier.ts index da5cc0a890a..bf4980150d9 100644 --- a/packages/utils/run-prettier.ts +++ b/packages/utils/run-prettier.ts @@ -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,