Skip to content

Commit

Permalink
Adding IgnorePlugin for momentjs. (#2)
Browse files Browse the repository at this point in the history
* Adding IgnorePlugin for momentjs.

* Added ability to override parsing of initial state

* Upgraded typescript to 3.9.x.

* Small fix.
  • Loading branch information
offbeatful authored May 14, 2020
1 parent 2d09843 commit 521d2de
Show file tree
Hide file tree
Showing 18 changed files with 9,314 additions and 9,246 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ The library uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) to
Default Configuration (see `packages/react-app/src/cli/options.ts`):
```json
{
appEntry: ".",
bootstrapModule: "@mocoding/react-app-basic",
outputClientPath: "./wwwroot",
outputServerPath: "./wwwroot_node",
"appEntry": ".",
"bootstrapModule": "@mocoding/react-app-basic",
"outputClientPath": "./wwwroot",
"outputServerPath": "./wwwroot_node",
}
```

Expand Down
10 changes: 0 additions & 10 deletions examples/extend-config/index.scss

This file was deleted.

8 changes: 0 additions & 8 deletions examples/extend-config/index.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions examples/extend-config/webpack.client.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/extend-config/webpack.server.config.js

This file was deleted.

6 changes: 0 additions & 6 deletions examples/extend-config/wtb.json

This file was deleted.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "mocoding-react-app-monorepo",
"private": true,
"devDependencies": {
"lerna": "^3.20.2",
"lerna": "^3.21.0",
"redux-thunk": "^2.3.0",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
},
"workspaces": [
"packages/*"
Expand All @@ -15,7 +15,10 @@
"scripts": {
"cli": "moapp",
"version": "lerna version --no-git-tag-version --yes",
"build": "yarn workspace @mocoding/react-app build"
"build": "yarn workspace @mocoding/react-app build",
"basic": "yarn cli serve --config examples/basic/.moapp.json",
"redux": "yarn cli serve --config examples/router-redux/.moapp.json",
"redux-async": "yarn cli serve --config examples/router-redux-async/.moapp.json"
},
"eslintConfig": {
"extends": "@mocoding/eslint-config"
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"prettier.js"
],
"dependencies": {
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-only-warn": "^1.0.2",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.20.0",
"eslint": "^7.0.0",
"prettier": "^2.0.5",
"typescript": "^3.8.3"
"typescript": "^3.9.2"
}
}
2 changes: 1 addition & 1 deletion packages/react-app-common/components/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Body extends React.Component<BodyProps> {
public render(): React.ReactNode {
const { scripts, markup, bodyAttrs } = this.props;

const type = process.env.SCRIPTS_TYPE || "module";
const type = process.env.MOAPP_SCRIPTS_TYPE || "text/javascript";

const renderScripts = scripts.map((scriptSrc, i) => (
<script type={type} src={scriptSrc} key={i} charSet="utf-8" />
Expand Down
8 changes: 4 additions & 4 deletions packages/react-app-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
},
"dependencies": {
"@hot-loader/react-dom": "^16.13.0",
"@types/react-dom": "^16.9.6",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.8",
"@types/react": "^16.9.35",
"@types/node": "^12.12.6",
"react-dom": "^16.13.1",
"react-helmet-async": "^1.0.5",
"react-hot-loader": "^4.12.20",
"react-helmet-async": "^1.0.6",
"react-hot-loader": "^4.12.21",
"react": "^16.13.1"
}
}
10 changes: 7 additions & 3 deletions packages/react-app-router-redux/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createBrowserHistory, History } from "history";
import * as Redux from "redux";
import { Context } from "@mocoding/react-app-common";

import { middlewares, reducers } from "injected-app-entry/store";
import { middlewares, reducers, onParseInitialState } from "injected-app-entry/store";
import devMiddlewares from "@mocoding/react-app-router-redux/middlewares";

export interface ReduxRouterState {
Expand Down Expand Up @@ -57,12 +57,16 @@ function configureStore<TState extends ReduxRouterState>(
return store;
}

function parseState<T>(serialized: string): T {
return onParseInitialState ? onParseInitialState(serialized) : JSON.parse(serialized);
}

export function createContext(abstractHistory?: History): Context {
const initialState =
const initialState: ReduxRouterState | undefined =
typeof window === "undefined" ||
typeof (window as any).__PRELOADED_STATE__ === "undefined"
? undefined
: JSON.parse((window as any)?.__PRELOADED_STATE__);
: parseState<ReduxRouterState>((window as any)?.__PRELOADED_STATE__);
const history = abstractHistory ?? createBrowserHistory();
return {
history,
Expand Down
7 changes: 3 additions & 4 deletions packages/react-app-router-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
},
"dependencies": {
"@mocoding/react-app-common": "^1.0.0",
"@types/react-redux": "^7.1.7",
"@types/react-redux": "^7.1.8",
"@types/react-router-dom": "^5.1.5",
"@types/redux-logger": "^3.0.7",
"@types/redux": "^3.6.0",
"@types/redux-logger": "^3.0.7",
"@types/webpack-env": "^1.15.2",
"connected-react-router": "^6.8.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-router-dom": "^5.2.0",
"redux-logger": "^3.0.6",
"redux": "^4.0.5"
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-app-router-redux/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ declare module "injected-app-entry/store" {
import { Middleware, Reducer } from "redux";
export const middlewares: Middleware[];
export const reducers: Reducer[];
export const onParseInitialState: (state: string) => unknown;
}
12 changes: 6 additions & 6 deletions packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
"chalk": "^4.0.0",
"commander": "^5.1.0",
"cosmiconfig": "^6.0.0",
"css-loader": "^3.5.2",
"css-loader": "^3.5.3",
"express": "^4.17.1",
"file-loader": "^6.0.0",
"fork-ts-checker-webpack-plugin": "^4.1.3",
"ignore-loader": "^0.1.2",
"import-glob": "^1.5.0",
"mini-css-extract-plugin": "^0.9.0",
"node-sass": "^4.14.0",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"prettier": "^2.0.5",
"sass-loader": "^8.0.2",
"terser-webpack-plugin": "^2.3.5",
"terser-webpack-plugin": "^3.0.1",
"ts-import-plugin": "^1.6.6",
"ts-loader": "^7.0.1",
"ts-loader": "^7.0.4",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"typescript": "^3.8.3",
"typescript": "^3.9.2",
"url-loader": "^4.1.0",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-dev-middleware": "^3.7.2",
Expand All @@ -57,6 +57,6 @@
"@types/optimize-css-assets-webpack-plugin": "^5.0.1",
"@types/terser-webpack-plugin": "^2.2.0",
"@types/webpack-bundle-analyzer": "^2.13.3",
"@types/webpack": "^4.41.12"
"@types/webpack": "^4.41.13"
}
}
1 change: 1 addition & 0 deletions packages/react-app/src/config/create-server-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function createServerConfig(
tsconfig: tsConfigLocation,
measureCompilationTime: false,
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
resolve: {
alias: {},
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/config/create-web-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function createWebConfig(
new MiniCssExtractPlugin({
filename: isProduction ? "[name].[contenthash:6].css" : "[name].css",
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
];

const rules: webpack.RuleSetRule[] = [
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function serverRenderer(stats: ServerRenderStats) {
const assets = jsonStats.assetsByChunkName;
const assetsUrls: string[] = [].concat(...Object.values(assets));
const defaultApiUrl = `${req.protocol}://${req.hostname}`;
const apiUrl = process.env.API_URL;
const apiUrl = process.env.MOAPP_API_URL;
const baseUrl = typeof apiUrl !== "undefined" ? apiUrl : defaultApiUrl;
const callback: RenderCallback = (error, result) => {
if (error) {
Expand Down
Loading

0 comments on commit 521d2de

Please sign in to comment.