Skip to content

Commit

Permalink
Merge pull request #47 from SokichiFujita/webpack-merge
Browse files Browse the repository at this point in the history
Webpack merge
  • Loading branch information
SokichiFujita authored Jul 25, 2020
2 parents cb589fb + f49af12 commit a47b7c8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bin/app/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const merge = require("webpack-merge");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const path = require("path");

Expand All @@ -9,8 +9,8 @@ const config = {
contentBase: path.resolve(__dirname, "public"),
historyApiFallback: true,
compress: true,
open: true
}
open: true,
},
};

module.exports = merge(common, config);
8 changes: 4 additions & 4 deletions bin/app/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const merge = require("webpack-merge");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
Expand All @@ -11,10 +11,10 @@ const config = {
new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: true,
reportFilename: "../analysis/bundle-analyzer.html"
reportFilename: "../analysis/bundle-analyzer.html",
}),
new WebpackBundleSizeAnalyzerPlugin("../analysis/bundle-size-analyzer.log")
]
new WebpackBundleSizeAnalyzerPlugin("../analysis/bundle-size-analyzer.log"),
],
};

module.exports = merge(common, config);
60 changes: 35 additions & 25 deletions bin/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module.exports.ContentFile = ({ prefix, ts }) => {
const typeArg = ts ? `: ${prefix}Props` : "";

const typeDef = ts
?
`
? `
type ${typeName} = {
title: string;
subtitle: string;
Expand Down Expand Up @@ -125,7 +124,7 @@ type ${prefix}State = {
text: string;
};
type ${prefix}Props = {};
type ${prefix}Props = Record<string, any>;
`
: ``;

Expand Down Expand Up @@ -256,14 +255,13 @@ const get${prefix}Action002 = () => ({
data: "RESULT OF YOUT ACTION",
});
${
ts
?
`
ts
? `
export type ${prefix}Actions = ReturnType<
typeof get${prefix}Action001 | typeof get${prefix}Action002
>;
`
: ""
: ""
}
export const ${prefix}ActionCreators = {
actionCreator001() {
Expand All @@ -285,30 +283,42 @@ export const ${prefix}ActionCreators = {
module.exports.AppConstantFile = ({ prefixes, ts }) => {
const actionTypeCode = prefixes
.map(
prefix =>
` ${prefix.toUpperCase()}_TYPE_001${ts ? " = " : ": "}"${prefix.toUpperCase()}_TYPE_001",
${prefix.toUpperCase()}_TYPE_002${ts ? " = " : ": "}"${prefix.toUpperCase()}_TYPE_002",
`).reduce((p, c) => p + c, "").slice(0,-1);

const actionCode = prefixes
.map(
prefix => `import { ${prefix}Actions } from "../actions/${prefix}ActionCreators";
`).reduce((p, c) => p + c, "");

const exportActionCode = prefixes.map(prefix => [`${prefix}Actions`, ` | `])
.reduce((p, c) => p.concat(c), [])
.slice(0, -1)
.reduce((p, c) => p + c, "")

const code = ts ? `${actionCode}
(prefix) =>
` ${prefix.toUpperCase()}_TYPE_001${
ts ? " = " : ": "
}"${prefix.toUpperCase()}_TYPE_001",
${prefix.toUpperCase()}_TYPE_002${
ts ? " = " : ": "
}"${prefix.toUpperCase()}_TYPE_002",
`
)
.reduce((p, c) => p + c, "")
.slice(0, -1);

const actionCode = prefixes
.map(
(
prefix
) => `import { ${prefix}Actions } from "../actions/${prefix}ActionCreators";
`
)
.reduce((p, c) => p + c, "");

const exportActionCode = prefixes
.map((prefix) => [`${prefix}Actions`, ` | `])
.reduce((p, c) => p.concat(c), [])
.slice(0, -1)
.reduce((p, c) => p + c, "");

const code = ts
? `${actionCode}
export type Actions = ${exportActionCode};
export enum ActionTypes {
${actionTypeCode}
}
`
:
`export const ActionTypes = {
: `export const ActionTypes = {
${actionTypeCode}
};
`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starter-react-flux",
"version": "5.3.0",
"version": "5.3.1",
"private": false,
"preferGlobal": true,
"scripts": {
Expand Down

0 comments on commit a47b7c8

Please sign in to comment.