Skip to content

Commit 88fcfa8

Browse files
committedMay 30, 2019
feat: add htmlWebpackPlugin in development
1 parent bd06a69 commit 88fcfa8

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed
 

‎packages/generators/init-generator.ts

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import entryQuestions from "./utils/entry";
1212
import langQuestionHandler, { LangType } from "./utils/languageSupport";
1313
import styleQuestionHandler, { Loader, StylingType } from "./utils/styleSupport";
1414
import tooltip from "./utils/tooltip";
15+
import { generatePluginName } from "./utils/plugins";
1516

1617
/**
1718
*
@@ -224,6 +225,19 @@ export default class InitGenerator extends Generator {
224225
);
225226
}
226227
}
228+
if(!this.isProd) {
229+
this.dependencies.push("html-webpack-plugin");
230+
const htmlWebpackDependency: string = "html-webpack-plugin";
231+
const htmlwebpackPlugin: string = generatePluginName(htmlWebpackDependency);
232+
(this.configuration.config.topScope as string[]).push(
233+
`const ${htmlwebpackPlugin} = require('${htmlWebpackDependency}')`,
234+
"\n",
235+
tooltip.html(),
236+
);
237+
(this.configuration.config.webpackOptions.plugins as string[]).push(
238+
`new ${htmlwebpackPlugin}()`,
239+
);
240+
}
227241
done();
228242
}
229243

‎packages/generators/utils/tooltip.ts

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ export default {
5757
*
5858
* https://github.com/webpack-contrib/terser-webpack-plugin
5959
*
60+
*/`;
61+
},
62+
63+
html: (): string => {
64+
return `/*
65+
* We've enabled HtmlWebpackPlugin for you! This generates a html
66+
* page for you when you compile webpack, which will make you start
67+
* developing and prototyping faster.
68+
*
69+
* https://github.com/jantimon/html-webpack-plugin
70+
*
6071
*/`;
6172
}
6273
};

‎packages/generators/utils/webpackConfig.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ export function getDefaultOptimization(isProd: boolean): WebpackOptions["optimiz
44
let optimizationOptions;
55
if (isProd) {
66
optimizationOptions = {
7+
minimizer: [
8+
"new TerserPlugin()",
9+
],
710
splitChunks: {
811
chunks: "'all'",
912
},
1013
};
1114
} else {
1215
optimizationOptions = {
13-
minimizer: [
14-
"new TerserPlugin()",
15-
],
1616
splitChunks: {
1717
cacheGroups: {
1818
vendors: {

‎packages/utils/run-prettier.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function runPrettier(outputPath: string, source: string, cb?: Fun
1919
try {
2020
prettySource = prettier.format(source, {
2121
filepath: outputPath,
22-
parser: "babylon",
22+
parser: "babel",
2323
singleQuote: true,
2424
tabWidth: 1,
2525
useTabs: true,

0 commit comments

Comments
 (0)
Please sign in to comment.