Skip to content

Commit

Permalink
fix(init): check defaults more precisely
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Oct 6, 2019
1 parent 3814d44 commit 51831c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
76 changes: 36 additions & 40 deletions packages/generators/init-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,53 +155,49 @@ export default class InitGenerator extends Generator {
"No",
this.autoGenerateConfig
);

if (this.langType === "No" && stylingType === "No") {
if (this.langType === "No") {
this.usingDefaults = true;
}

const { ExtractUseProps, regExpForStyles } = styleQuestionHandler(self, stylingType);
if (stylingType !== "No") {
this.usingDefaults = false;
}
// Ask if the user wants to use extractPlugin
const { useExtractPlugin } = await Input(
self,
"useExtractPlugin",
"If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)",
"main",
this.autoGenerateConfig
);

if (!this.usingDefaults) {
// Ask if the user wants to use extractPlugin
const { useExtractPlugin } = await Input(
self,
"useExtractPlugin",
"If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)",
"'main.css'",
this.autoGenerateConfig
if (regExpForStyles) {
const cssBundleName: string = useExtractPlugin;
this.dependencies.push("mini-css-extract-plugin");
this.configuration.config.topScope.push(
tooltip.cssPlugin(),
"const MiniCssExtractPlugin = require('mini-css-extract-plugin');",
"\n"
);
if (cssBundleName.length !== 0) {
(this.configuration.config.webpackOptions.plugins as string[]).push(
// TODO: use [contenthash] after it is supported
`new MiniCssExtractPlugin({ filename:'${cssBundleName}.[chunkhash].css' })`
);
} else {
(this.configuration.config.webpackOptions.plugins as string[]).push(
"new MiniCssExtractPlugin({ filename:'style.css' })"
);
}

if (regExpForStyles) {
if (this.isProd) {
const cssBundleName: string = useExtractPlugin;
this.dependencies.push("mini-css-extract-plugin");
this.configuration.config.topScope.push(
tooltip.cssPlugin(),
"const MiniCssExtractPlugin = require('mini-css-extract-plugin');",
"\n"
);
if (cssBundleName.length !== 0) {
(this.configuration.config.webpackOptions.plugins as string[]).push(
// TODO: use [contenthash] after it is supported
`new MiniCssExtractPlugin({ filename:'${cssBundleName}.[chunkhash].css' })`
);
} else {
(this.configuration.config.webpackOptions.plugins as string[]).push(
"new MiniCssExtractPlugin({ filename:'style.css' })"
);
}

ExtractUseProps.unshift({
loader: "MiniCssExtractPlugin.loader"
});
}
ExtractUseProps.unshift({
loader: "MiniCssExtractPlugin.loader"
});

this.configuration.config.webpackOptions.module.rules.push({
test: regExpForStyles,
use: ExtractUseProps
});
}
this.configuration.config.webpackOptions.module.rules.push({
test: regExpForStyles,
use: ExtractUseProps
});
}
if (this.usingDefaults) {
// Html webpack Plugin
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/modify-config-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function modifyHelperUtil(action: string, generator: typeof Gener
},
configModule,
);
if (configModule.usingDefaults) {
if (configModule.usingDefaults && configModule.usingDefaults === true) {
const runCommand = getPackageManager() === "yarn" ? "yarn build" : "npm run build";

const successMessage =
Expand Down

0 comments on commit 51831c7

Please sign in to comment.