@dr.pogodin/react-utils 1.25.6 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.js +3 -1
- package/bin/build.js +18 -4
- package/build/development/client/getInj.js +9 -8
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +6 -3
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +4 -0
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +166 -38
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +13 -13
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +16 -23
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +56 -43
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +9 -5
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +12 -9
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -2
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +7 -5
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +24 -26
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +24 -17
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +44 -37
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +7 -7
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +10 -9
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +22 -18
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +16 -16
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +10 -9
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +16 -18
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +27 -7
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +14 -22
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +19 -21
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +11 -10
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +15 -13
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +2 -2
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +15 -0
- package/build/development/shared/utils/globalState.js.map +1 -0
- package/build/development/shared/utils/index.js +13 -10
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +7 -3
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +35 -28
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +17 -0
- package/build/development/shared/utils/jest/global.js.map +1 -0
- package/build/development/shared/utils/jest/index.js +17 -9
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +25 -34
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +16 -12
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +3 -3
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/web.bundle.js +92 -82
- package/build/production/client/getInj.js +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +4 -4
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +3 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +7 -8
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +5 -4
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +32 -30
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +7 -5
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -10
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +1 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +3 -3
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +11 -11
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js +11 -11
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +25 -20
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +7 -7
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +2 -2
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +10 -10
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -2
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js +7 -3
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +13 -13
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +3 -3
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +7 -7
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +3 -0
- package/build/production/shared/utils/globalState.js.map +1 -0
- package/build/production/shared/utils/index.js +2 -2
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +7 -4
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +9 -9
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +2 -0
- package/build/production/shared/utils/jest/global.js.map +1 -0
- package/build/production/shared/utils/jest/index.js +5 -5
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +16 -16
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +12 -8
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +3 -3
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +3 -0
- package/build/types-code/client/index.d.ts +11 -0
- package/build/types-code/client/init.d.ts +9 -0
- package/build/types-code/index.d.ts +10 -0
- package/build/types-code/server/Cache.d.ts +37 -0
- package/build/types-code/server/index.d.ts +145 -0
- package/build/types-code/server/renderer.d.ts +106 -0
- package/build/types-code/server/server.d.ts +41 -0
- package/build/types-code/server/utils/errors.d.ts +104 -0
- package/build/types-code/server/utils/index.d.ts +1 -0
- package/build/types-code/shared/components/Button/index.d.ts +27 -0
- package/build/types-code/shared/components/Checkbox/index.d.ts +21 -0
- package/build/types-code/shared/components/Dropdown/index.d.ts +23 -0
- package/build/types-code/shared/components/GenericLink/index.d.ts +61 -0
- package/build/types-code/shared/components/Input/index.d.ts +11 -0
- package/build/types-code/shared/components/Link.d.ts +12 -0
- package/build/types-code/shared/components/MetaTags.d.ts +68 -0
- package/build/types-code/shared/components/Modal/index.d.ts +26 -0
- package/build/types-code/shared/components/NavLink.d.ts +5 -0
- package/build/types-code/shared/components/PageLayout/index.d.ts +16 -0
- package/build/types-code/shared/components/ScalableRect/index.d.ts +19 -0
- package/build/types-code/shared/components/Throbber/index.d.ts +9 -0
- package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +23 -0
- package/build/types-code/shared/components/WithTooltip/index.d.ts +17 -0
- package/build/types-code/shared/components/YouTubeVideo/index.d.ts +13 -0
- package/build/types-code/shared/components/index.d.ts +16 -0
- package/build/types-code/shared/utils/config.d.ts +2 -0
- package/build/types-code/shared/utils/globalState.d.ts +20 -0
- package/build/types-code/shared/utils/index.d.ts +52 -0
- package/build/types-code/shared/utils/isomorphy/buildInfo.d.ts +23 -0
- package/build/types-code/shared/utils/isomorphy/environment-check.d.ts +11 -0
- package/build/types-code/shared/utils/isomorphy/index.d.ts +20 -0
- package/build/types-code/shared/utils/jest/E2eSsrEnv.d.ts +31 -0
- package/build/types-code/shared/utils/jest/global.d.ts +12 -0
- package/build/types-code/shared/utils/jest/index.d.ts +85 -0
- package/build/types-code/shared/utils/splitComponent.d.ts +41 -0
- package/build/types-code/shared/utils/time.d.ts +62 -0
- package/build/types-code/shared/utils/webpack.d.ts +18 -0
- package/build/types-scss/__tests__/js/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/publicPath support/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/components/NavLink/styles.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
- package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Button/style.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +9 -0
- package/build/types-scss/src/shared/components/GenericLink/style.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/Input/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/Modal/base-theme.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/PageLayout/base-theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/ScalableRect/style.scss.d.ts +2 -0
- package/build/types-scss/src/shared/components/Throbber/theme.scss.d.ts +6 -0
- package/build/types-scss/src/shared/components/WithTooltip/default-theme.scss.d.ts +7 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/base.scss.d.ts +5 -0
- package/build/types-scss/src/shared/components/YouTubeVideo/throbber.scss.d.ts +4 -0
- package/config/eslint/jest.json +3 -2
- package/config/eslint/typescript.js +34 -0
- package/config/jest/default.js +3 -3
- package/package.json +74 -32
- package/src/client/getInj.ts +43 -0
- package/src/client/index.tsx +40 -0
- package/src/client/init.ts +47 -0
- package/src/index.ts +58 -0
- package/src/server/Cache.ts +68 -0
- package/src/server/index.ts +230 -0
- package/src/server/renderer.tsx +604 -0
- package/src/server/server.ts +309 -0
- package/src/server/utils/errors.ts +135 -0
- package/src/server/utils/index.ts +3 -0
- package/src/shared/components/Button/index.tsx +146 -0
- package/src/shared/components/Button/style.scss +53 -0
- package/src/shared/components/Checkbox/index.tsx +71 -0
- package/src/shared/components/Checkbox/theme.scss +43 -0
- package/src/shared/components/Dropdown/index.tsx +144 -0
- package/src/shared/components/Dropdown/theme.scss +63 -0
- package/src/shared/components/GenericLink/index.tsx +157 -0
- package/src/shared/components/GenericLink/style.scss +3 -0
- package/src/shared/components/Input/index.tsx +59 -0
- package/src/shared/components/Input/theme.scss +27 -0
- package/src/shared/components/Link.tsx +21 -0
- package/src/shared/components/MetaTags.tsx +170 -0
- package/src/shared/components/Modal/base-theme.scss +38 -0
- package/src/shared/components/Modal/index.tsx +144 -0
- package/src/shared/components/Modal/styles.scss +5 -0
- package/src/shared/components/NavLink.tsx +13 -0
- package/src/shared/components/PageLayout/base-theme.scss +30 -0
- package/src/shared/components/PageLayout/index.tsx +76 -0
- package/src/shared/components/ScalableRect/index.tsx +84 -0
- package/src/shared/components/ScalableRect/style.scss +10 -0
- package/src/shared/components/Throbber/index.tsx +43 -0
- package/src/shared/components/Throbber/theme.scss +26 -0
- package/src/shared/components/WithTooltip/Tooltip.tsx +353 -0
- package/src/shared/components/WithTooltip/default-theme.scss +36 -0
- package/src/shared/components/WithTooltip/index.tsx +204 -0
- package/src/shared/components/YouTubeVideo/base.scss +13 -0
- package/src/shared/components/YouTubeVideo/index.tsx +96 -0
- package/src/shared/components/YouTubeVideo/throbber.scss +11 -0
- package/src/shared/components/index.ts +17 -0
- package/src/shared/utils/config.ts +21 -0
- package/src/shared/utils/globalState.ts +29 -0
- package/src/shared/utils/index.ts +105 -0
- package/src/shared/utils/isomorphy/buildInfo.ts +54 -0
- package/src/shared/utils/isomorphy/environment-check.ts +18 -0
- package/src/shared/utils/isomorphy/index.ts +38 -0
- package/src/shared/utils/jest/E2eSsrEnv.ts +250 -0
- package/src/shared/utils/jest/global.ts +19 -0
- package/src/shared/utils/jest/index.tsx +157 -0
- package/src/shared/utils/splitComponent.tsx +255 -0
- package/src/shared/utils/time.ts +118 -0
- package/src/shared/utils/webpack.ts +45 -0
- package/src/styles/_global/reset.css +52 -0
- package/src/styles/global.scss +11 -0
- package/tsconfig.configs.json +18 -0
- package/tsconfig.json +27 -0
- package/tsconfig.types.json +53 -0
- package/typed-scss-modules.config.ts +9 -0
- package/types.d.ts +37 -0
- package/{webpack.config.js → webpack.config.ts} +7 -3
- package/config/babel/node-ssr.js +0 -85
- package/config/babel/webpack.js +0 -123
- package/config/webpack/app-base.js +0 -330
- package/config/webpack/app-development.js +0 -80
- package/config/webpack/app-production.js +0 -60
- package/config/webpack/lib-base.js +0 -155
- package/config/webpack/lib-development.js +0 -45
- package/config/webpack/lib-production.js +0 -44
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// TS config for ESLint, editor plugins, and other tools that look-up and use
|
|
2
|
+
// the default tsconfig.json file.
|
|
3
|
+
{
|
|
4
|
+
// Note: Full relative paths, as some tools don't support Node module
|
|
5
|
+
// resolution mechanics.
|
|
6
|
+
"extends": "./node_modules/@tsconfig/recommended/tsconfig.json",
|
|
7
|
+
|
|
8
|
+
// Keep these in case any mocks / tests are declared within "src" code tree.
|
|
9
|
+
"exclude": [
|
|
10
|
+
"**/__mocks__/**",
|
|
11
|
+
"**/__tests__/**",
|
|
12
|
+
],
|
|
13
|
+
|
|
14
|
+
"include": [
|
|
15
|
+
"src",
|
|
16
|
+
"types.d.ts",
|
|
17
|
+
],
|
|
18
|
+
"compilerOptions": {
|
|
19
|
+
"declaration": true,
|
|
20
|
+
"emitDeclarationOnly": true,
|
|
21
|
+
"jsx": "react-jsx",
|
|
22
|
+
|
|
23
|
+
// BEWARE: Different settings are likely to transform dynamic import()
|
|
24
|
+
// statements in the code, thus breaking Webpack's code splitting.
|
|
25
|
+
// See: https://davidea.st/articles/webpack-typescript-code-split-wont-work
|
|
26
|
+
"module": "ESNext",
|
|
27
|
+
"moduleResolution": "Node",
|
|
28
|
+
|
|
29
|
+
"outDir": "build/types-code",
|
|
30
|
+
|
|
31
|
+
"paths": {
|
|
32
|
+
// BEWARE: Don't do this, as in other TS config files:
|
|
33
|
+
//
|
|
34
|
+
// "*": ["./src/shared/*", "./src/*", "./*"]
|
|
35
|
+
//
|
|
36
|
+
// "ts-alias" does not act on "*" rule, as we need to get correctly
|
|
37
|
+
// resolved relative paths in the generated .d.ts files, so that they
|
|
38
|
+
// can work in host projects.
|
|
39
|
+
|
|
40
|
+
"components": ["./src/shared/components"],
|
|
41
|
+
"components/*": ["./src/shared/components/*"],
|
|
42
|
+
"server/*": ["./src/server/*"],
|
|
43
|
+
"utils": ["./src/shared/utils"],
|
|
44
|
+
"utils/*": ["./src/shared/utils/*"],
|
|
45
|
+
},
|
|
46
|
+
"rootDirs": [".", "build/types-scss"],
|
|
47
|
+
"strict": true,
|
|
48
|
+
|
|
49
|
+
// This ensures TypeScript does not remove unused imports, which may cause
|
|
50
|
+
// troubles when we rely on some side-effects from imported modules.
|
|
51
|
+
"verbatimModuleSyntax": true,
|
|
52
|
+
},
|
|
53
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare module '@babel/register/experimental-worker' {
|
|
2
|
+
const register: {
|
|
3
|
+
(args: {
|
|
4
|
+
envName: string;
|
|
5
|
+
extensions: string[];
|
|
6
|
+
root: string;
|
|
7
|
+
}): void;
|
|
8
|
+
revert: () => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default register;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO: This should be done inside my CSURF fork itself.
|
|
15
|
+
declare module '@dr.pogodin/csurf' {
|
|
16
|
+
import F from 'csurf';
|
|
17
|
+
|
|
18
|
+
export default F;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module 'node-forge/lib/forge' {
|
|
22
|
+
import F from 'node-forge';
|
|
23
|
+
|
|
24
|
+
export default F;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '*.png' {
|
|
28
|
+
export default string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare namespace React {
|
|
32
|
+
// This allows all JSX elements to have additional "styleName" attribute,
|
|
33
|
+
// handled by "@dr.pogodin/babel-plugin-react-css-modules".
|
|
34
|
+
interface Attributes {
|
|
35
|
+
styleName?: string;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/* eslint-disable global-require */
|
|
2
2
|
/* eslint-disable import/no-dynamic-require */
|
|
3
3
|
|
|
4
|
-
module.exports = function buildConfig(env) {
|
|
5
|
-
|
|
4
|
+
module.exports = function buildConfig(env: string) {
|
|
5
|
+
let factory = require(`./config/webpack/lib-${env}.js`);
|
|
6
|
+
factory = 'default' in factory ? factory.default : factory;
|
|
7
|
+
|
|
8
|
+
const config = factory({
|
|
6
9
|
context: __dirname,
|
|
7
10
|
entry: './src',
|
|
8
11
|
library: '@dr.pogodin/react-utils',
|
|
12
|
+
typescript: true,
|
|
9
13
|
});
|
|
10
14
|
|
|
11
15
|
/* The lib config is intended for use outside of this very package,
|
|
12
16
|
* so we need some tweaks here to make it work for this package itself. */
|
|
13
17
|
const babelLoader = config.module.rules.find(
|
|
14
|
-
(x) => x.loader === 'babel-loader',
|
|
18
|
+
(x: { loader: string }) => x.loader === 'babel-loader',
|
|
15
19
|
);
|
|
16
20
|
babelLoader.options.presets[0][0] = `${__dirname}/config/babel/webpack`;
|
|
17
21
|
|
package/config/babel/node-ssr.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
|
|
3
|
-
const { pick, pull } = require('lodash');
|
|
4
|
-
const getWebpackBabelConfig = require('./webpack');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new base config.
|
|
8
|
-
* @param {object} babel Babel compiler.
|
|
9
|
-
* @param {object} [options] It supports all options of
|
|
10
|
-
* {@link module:babel/webpack.getPreset babel/webpack's getPreset()},
|
|
11
|
-
* but it overrides `targets` option with `current node` value, and further
|
|
12
|
-
* accepts the following:
|
|
13
|
-
* @param {string} [options.baseAssetsOutputPath] Path prefix for emitted
|
|
14
|
-
* image assets.
|
|
15
|
-
* @return {object} Created config object.
|
|
16
|
-
* @ignore
|
|
17
|
-
*/
|
|
18
|
-
function newBase(babel, options = {}) {
|
|
19
|
-
const baseOps = pick(options, ['noStyling']);
|
|
20
|
-
const config = getWebpackBabelConfig(
|
|
21
|
-
babel,
|
|
22
|
-
{ ...baseOps, targets: 'current node' },
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const baseAssetsOutputPath = options.baseAssetsOutputPath || '';
|
|
26
|
-
config.plugins.push(
|
|
27
|
-
['@dr.pogodin/transform-assets', {
|
|
28
|
-
extensions: ['gif', 'jpeg', 'jpg', 'png'],
|
|
29
|
-
name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
|
|
30
|
-
}],
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const moduleResolverPluginOps = config.plugins.find(
|
|
34
|
-
(x) => x[0] === 'module-resolver',
|
|
35
|
-
)[1];
|
|
36
|
-
moduleResolverPluginOps.transformFunctions = [
|
|
37
|
-
'requireWeak',
|
|
38
|
-
'resolveWeak',
|
|
39
|
-
'webpack.requireWeak',
|
|
40
|
-
'webpack.resolveWeak',
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
if (babel.env() === getWebpackBabelConfig.ENVIRONMENTS.DEV) {
|
|
44
|
-
pull(config.plugins, 'react-refresh/babel');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return config;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Updates given `config` with styling ((S)CSS-related) setup.
|
|
52
|
-
*
|
|
53
|
-
* **Beware:** It mutates `config`.
|
|
54
|
-
*
|
|
55
|
-
* @param {object} config
|
|
56
|
-
* @return {object} Returns mutated config for chaining.
|
|
57
|
-
* @ignore
|
|
58
|
-
*/
|
|
59
|
-
function addStyling(config) {
|
|
60
|
-
const cssModulesOps = config.plugins.find(
|
|
61
|
-
([name]) => name === '@dr.pogodin/react-css-modules',
|
|
62
|
-
)[1];
|
|
63
|
-
cssModulesOps.replaceImport = true;
|
|
64
|
-
return config;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Generates Babel config for NodeJS compilation and server-side execution.
|
|
69
|
-
* @param {object} babel Babel compiler instance.
|
|
70
|
-
* @param {object} [ops] Preset options. It supports all options accepted by
|
|
71
|
-
* the underlying {@link module:babel/webpack preset for Webpack}, but it
|
|
72
|
-
* overrides `targets` option by `current node` value, and also accepts
|
|
73
|
-
* the following additional options:
|
|
74
|
-
* @param {string} [ops.baseAssetsOutputPath] Path prefix for emitted image
|
|
75
|
-
* assets.
|
|
76
|
-
* @return {object} Generated config.
|
|
77
|
-
*/
|
|
78
|
-
function getConfig(babel, ops = {}) {
|
|
79
|
-
const env = babel.env();
|
|
80
|
-
const config = newBase(babel, ops);
|
|
81
|
-
if (!ops.noStyling) addStyling(config, env);
|
|
82
|
-
return config;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = getConfig;
|
package/config/babel/webpack.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
const { pick } = require('lodash');
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
generateScopedNameFactory,
|
|
5
|
-
} = require('@dr.pogodin/babel-plugin-react-css-modules/utils');
|
|
6
|
-
|
|
7
|
-
const generateScopedNameDev = generateScopedNameFactory(
|
|
8
|
-
'[package]___[path][name]___[local]___[hash:base64:6]',
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
const generateScopedNameProd = generateScopedNameFactory(
|
|
12
|
-
'[hash:base64:6]',
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @static
|
|
17
|
-
* @desc
|
|
18
|
-
* ```js
|
|
19
|
-
* import { ENVIRONMENTS } from '@dr.pogodin/react-utils/config/babel/webpack';
|
|
20
|
-
* ```
|
|
21
|
-
* Supported Babel environments.
|
|
22
|
-
* @prop {string} DEV `development`
|
|
23
|
-
* @prop {string} PROD `production`
|
|
24
|
-
* @prop {string} TEST `test`
|
|
25
|
-
*/
|
|
26
|
-
const ENVIRONMENTS = {
|
|
27
|
-
DEV: 'development',
|
|
28
|
-
PROD: 'production',
|
|
29
|
-
TEST: 'test',
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new base config.
|
|
34
|
-
* @param {object} [options] Base config options.
|
|
35
|
-
* @param {string|string[]|object} [options.targets=defaults]
|
|
36
|
-
* `@babel/preset-env` targets.
|
|
37
|
-
* @return {object} Generated config.
|
|
38
|
-
* @ignore
|
|
39
|
-
*/
|
|
40
|
-
function newBaseConfig(options = {}) {
|
|
41
|
-
return {
|
|
42
|
-
presets: [
|
|
43
|
-
// Chrome 69 is the browser for Android API 28.
|
|
44
|
-
['@babel/env', { targets: options.targets || 'defaults or chrome >= 69' }],
|
|
45
|
-
|
|
46
|
-
// TODO: Starting from Babel 8, "automatic" will be the default runtime,
|
|
47
|
-
// thus once upgraded to Babel 8, runtime should be removed from
|
|
48
|
-
// @babel/react options below.
|
|
49
|
-
['@babel/react', { runtime: 'automatic' }],
|
|
50
|
-
|
|
51
|
-
'@dr.pogodin/babel-preset-svgr',
|
|
52
|
-
],
|
|
53
|
-
plugins: [
|
|
54
|
-
['module-resolver', {
|
|
55
|
-
extensions: ['.js', '.jsx'],
|
|
56
|
-
root: [
|
|
57
|
-
'./src/shared',
|
|
58
|
-
'./src',
|
|
59
|
-
],
|
|
60
|
-
}],
|
|
61
|
-
'@babel/transform-runtime',
|
|
62
|
-
],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Updates given `config` with styling ((S)CSS-related) setup.
|
|
68
|
-
*
|
|
69
|
-
* **Beware:** It mutates `config`.
|
|
70
|
-
*
|
|
71
|
-
* @param {object} config
|
|
72
|
-
* @param {string} env Target environment: `development` or `production`.
|
|
73
|
-
* @return {object} Returns mutated config for chaining.
|
|
74
|
-
* @ignore
|
|
75
|
-
*/
|
|
76
|
-
function addStyling(config, env) {
|
|
77
|
-
const cssModulesOps = {
|
|
78
|
-
autoResolveMultipleImports: true,
|
|
79
|
-
filetypes: {
|
|
80
|
-
'.scss': { syntax: 'postcss-scss' },
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
config.plugins.push(['@dr.pogodin/react-css-modules', cssModulesOps]);
|
|
84
|
-
switch (env) {
|
|
85
|
-
case ENVIRONMENTS.DEV:
|
|
86
|
-
case ENVIRONMENTS.TEST:
|
|
87
|
-
cssModulesOps.generateScopedName = generateScopedNameDev;
|
|
88
|
-
break;
|
|
89
|
-
case ENVIRONMENTS.PROD:
|
|
90
|
-
cssModulesOps.generateScopedName = generateScopedNameProd;
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
93
|
-
}
|
|
94
|
-
return config;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Generates Babel preset for Webpack.
|
|
99
|
-
* @param {object} babel Babel compiler.
|
|
100
|
-
* @param {object} [ops] Preset options.
|
|
101
|
-
* @param {boolean} [ops.noRR] If truthy `react-refresh/babel` plugin is not
|
|
102
|
-
* included into config, no matter the environment.
|
|
103
|
-
* @param {boolean} [ops.noStyling] If truthy all setup related to styling
|
|
104
|
-
* ((S)CSS processing) will be skipped.
|
|
105
|
-
* @param {string|string[]|object} [ops.targets=defaults] Targets for
|
|
106
|
-
* `@babel/preset-env`.
|
|
107
|
-
* @return {object} Generated config.
|
|
108
|
-
*/
|
|
109
|
-
function getPreset(babel, ops = {}) {
|
|
110
|
-
const env = babel.env();
|
|
111
|
-
|
|
112
|
-
const baseOps = pick(ops, ['targets']);
|
|
113
|
-
const res = newBaseConfig(baseOps);
|
|
114
|
-
|
|
115
|
-
if (!ops.noStyling) addStyling(res, env);
|
|
116
|
-
if (env === ENVIRONMENTS.DEV && !ops.noRR) {
|
|
117
|
-
res.plugins.push('react-refresh/babel');
|
|
118
|
-
}
|
|
119
|
-
return res;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = getPreset;
|
|
123
|
-
module.exports.ENVIRONMENTS = ENVIRONMENTS;
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @category Configs
|
|
3
|
-
* @module webpack/app-base
|
|
4
|
-
* @desc
|
|
5
|
-
* Base [Webpack](https://webpack.js.org/) configuration for apps.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const nodeFs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
clone,
|
|
13
|
-
defaults,
|
|
14
|
-
isFunction,
|
|
15
|
-
isObject,
|
|
16
|
-
} = require('lodash');
|
|
17
|
-
|
|
18
|
-
const autoprefixer = require('autoprefixer');
|
|
19
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
20
|
-
const forge = require('node-forge');
|
|
21
|
-
const SM = require('sitemap');
|
|
22
|
-
const { DefinePlugin, ProgressPlugin } = require('webpack');
|
|
23
|
-
const WorkboxPlugin = require('workbox-webpack-plugin');
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
getLocalIdent,
|
|
27
|
-
} = require('@dr.pogodin/babel-plugin-react-css-modules/utils');
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new Webpack config object, and performs some auxiliary operations
|
|
31
|
-
* on the way.
|
|
32
|
-
* @param {object} ops Configuration params. This allows to modify some
|
|
33
|
-
* frequently changed options in a convenient way, without a need to manipulate
|
|
34
|
-
* directly with the created config object.
|
|
35
|
-
* @param {string} ops.babelEnv Babel environment to use for the Babel
|
|
36
|
-
* compilation step.
|
|
37
|
-
* @param {object} [ops.babelLoaderOptions] Overrides for default Babel options
|
|
38
|
-
* of JSX and SVG files loader.
|
|
39
|
-
* @param {string} ops.context Base URL for resolution of relative config paths.
|
|
40
|
-
* @param {string} [ops.cssLocalIdent=hash:base64:6] The template for
|
|
41
|
-
* CSS classnames generation by the Webpack's `css-loader`; it is passed into
|
|
42
|
-
* the `localIdentName` param of the loader. It should match the corresponding
|
|
43
|
-
* setting in the Babel config.
|
|
44
|
-
* @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
|
|
45
|
-
* be created at the disk during the compilation.
|
|
46
|
-
* @param {boolean} [ops.dontUseProgressPlugin] Set to not include progress
|
|
47
|
-
* plugin.
|
|
48
|
-
* @param {string|string[]} ops.entry Entry points for "main" chunk. The config
|
|
49
|
-
* will prepend them by some necessary polyfills, e.g.:
|
|
50
|
-
* ([babel-polyfill](https://babeljs.io/docs/usage/polyfill/),
|
|
51
|
-
* [nodelist-foreach-polyfill](https://www.npmjs.com/package/nodelist-foreach-polyfill)).
|
|
52
|
-
* @param {boolean|object} ops.workbox If evaluates to a truthy value,
|
|
53
|
-
* [Workbox's InjectManifest plugin](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#injectmanifest_plugin)
|
|
54
|
-
* is added to the array of Webpack plugins, to generate service worker for
|
|
55
|
-
* browser. If the value is an object, it is merged into the options passed
|
|
56
|
-
* into the plugin, otherwise default options are used:
|
|
57
|
-
* ```json
|
|
58
|
-
* {
|
|
59
|
-
* "importWorkboxFrom": "local",
|
|
60
|
-
* "swSrc": "@dr.pogodin/react-utils/config/workbox/default.js",
|
|
61
|
-
* "swDest": "__service-worker.js"
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
* If service worker is generated by this option, it will be automatically
|
|
65
|
-
* initiated at the client side by the standard
|
|
66
|
-
* [client-side initialization script](docs/client.md)
|
|
67
|
-
* provided by **@dr.pogodin/react-utils**. Note that `swDest`'s value cannot be
|
|
68
|
-
* overriden by config options provided via `workbox` object.
|
|
69
|
-
* @param {object} [ops.fs] Filesystem to use instead of the Node's FS.
|
|
70
|
-
* @param {boolean|object} [ops.keepBuildInfo] If `true` and a `.build-info`
|
|
71
|
-
* file from a previous build exists in the context directory, it will be
|
|
72
|
-
* loaded and used, rather than re-generated by the config factory. It allows
|
|
73
|
-
* to re-create the Webpack config during a server launch without re-generation
|
|
74
|
-
* of the build info file created during a previous build (and thus bundled
|
|
75
|
-
* into the frontend bundle). If an object is provided, it will be used as
|
|
76
|
-
* the build info, instead of trying to load it from the filesystem. This
|
|
77
|
-
* feature is intended for testing context.
|
|
78
|
-
* @param {string} ops.mode
|
|
79
|
-
* [Webpack mode](https://webpack.js.org/concepts/mode/).
|
|
80
|
-
* @param {string} [ops.outputPath=build] Optional. Output path for the build.
|
|
81
|
-
* @param {string} ops.publicPath Base URL for the output of the build assets.
|
|
82
|
-
* @param {string} [ops.sitemap] The path to JS or JSON config for sitemap.
|
|
83
|
-
* It can be relative to the context, and can be a factory, which returns
|
|
84
|
-
* the config. The config should be compatible with
|
|
85
|
-
* [`sitemap`](https://www.npmjs.com/package/sitemap) library, and if
|
|
86
|
-
* provided the Webpack config factory will use it to gererate `sitemap.xml`
|
|
87
|
-
* file in the output folder, and then serve it from the app root.
|
|
88
|
-
* @return The generated config will opt to:
|
|
89
|
-
* - Bundle the font assets (EOF, OTF, SVG, TTF, WOFF, WOFF2 files from
|
|
90
|
-
* the `src/assets/fonts` folder of your source code will be bundled
|
|
91
|
-
* and output into the `[PUBLIC_PATH]/fonts` folder);
|
|
92
|
-
* - Bundle image assets (GIF, JPEG, JPG, PNG files from any folder of
|
|
93
|
-
* your source code will be bundled and output into the
|
|
94
|
-
* `[PUBLIC_PATH]/images` folder);
|
|
95
|
-
* - Bundle SCSS files from any folder of your source code, beside
|
|
96
|
-
* `node_modules` and its subfolders. The files will be compiled,
|
|
97
|
-
* bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
|
|
98
|
-
* bundles;
|
|
99
|
-
* - Bundle CSS files from any folder of your code. The files will be
|
|
100
|
-
* bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
|
|
101
|
-
* bundles;
|
|
102
|
-
* - Bundle JS, JSX, and SVG files; they will be compiled into the
|
|
103
|
-
* `[PUBLIC_PATH]/[CHUNK_NAME].js` bundles, using the Babel environment
|
|
104
|
-
* specified in the factory options, and
|
|
105
|
-
* [`config/babel/webpack`](./babel-config.js#webpack) config.
|
|
106
|
-
*
|
|
107
|
-
* - The following path aliases will be automatically set:
|
|
108
|
-
* - **`assets`** for `[CONTEXT]/src/assets`;
|
|
109
|
-
* - **`components`** for `[CONTEXT]/src/shared/components`;
|
|
110
|
-
* - **`fonts`** for `[CONTEXT]/src/assets/fonts`;
|
|
111
|
-
* - **`styles`** for `[CONTEXT]/src/styles`.
|
|
112
|
-
*
|
|
113
|
-
* Also `resolve.symlinks` Webpack option is set to *false* to avoid problems
|
|
114
|
-
* with resolution of assets from packages linked with `npm link`.
|
|
115
|
-
*
|
|
116
|
-
* - The following global variables will be emulated inside the output
|
|
117
|
-
* JS bundle:
|
|
118
|
-
* - **`BUILD_RNDKEY`** — A random 32 bit key that can be used
|
|
119
|
-
* for encryption, it is set just as a global variable accessible in
|
|
120
|
-
* the code;
|
|
121
|
-
* - **`BUILD_TIMESTAMP`** — UTC timestamp of the beginning of
|
|
122
|
-
* the build;
|
|
123
|
-
* - **`FRONT_END`** — It will be set *true* inside the bundle,
|
|
124
|
-
* so that shared code can use it to determine that it is executed
|
|
125
|
-
* at the client side.
|
|
126
|
-
*
|
|
127
|
-
* - It also opts to polyfill the `__dirname` global variable,
|
|
128
|
-
* and to ignore imports of the `fs` Node package;
|
|
129
|
-
*
|
|
130
|
-
* - Also, it will store to the disk (re-writes if exists) the file
|
|
131
|
-
* `[CONTEXT]/.build-info` which will contain a stringified JSON
|
|
132
|
-
* object with the following fields:
|
|
133
|
-
* - **`rndkey`** — The value set for `BUILD_RNDKEY`;
|
|
134
|
-
* - **`timestamp`** — The value set for `BUILD_TIMESTAMP`.
|
|
135
|
-
*/
|
|
136
|
-
module.exports = function configFactory(ops) {
|
|
137
|
-
const o = defaults(clone(ops), {
|
|
138
|
-
babelLoaderOptions: {},
|
|
139
|
-
cssLocalIdent: '[hash:base64:6]',
|
|
140
|
-
outputPath: 'build/web-public',
|
|
141
|
-
publicPath: '',
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const fs = ops.fs || nodeFs;
|
|
145
|
-
|
|
146
|
-
/* TODO: This works in practice, but being async and not awaited it is a bad
|
|
147
|
-
* pattern. */
|
|
148
|
-
if (o.sitemap) {
|
|
149
|
-
const sitemapUrl = path.resolve(o.context, o.sitemap);
|
|
150
|
-
/* eslint-disable global-require, import/no-dynamic-require */
|
|
151
|
-
let source = require(sitemapUrl);
|
|
152
|
-
if (isFunction(source)) source = source();
|
|
153
|
-
/* eslint-enable global-require, import/no-dynamic-require */
|
|
154
|
-
const sm = new SM.SitemapStream();
|
|
155
|
-
source.forEach((item) => sm.write(item));
|
|
156
|
-
sm.end();
|
|
157
|
-
SM.streamToPromise(sm).then((sitemap) => {
|
|
158
|
-
const outUrl = path.resolve(o.context, o.outputPath);
|
|
159
|
-
if (!fs.existsSync(outUrl)) fs.mkdirSync(outUrl);
|
|
160
|
-
fs.writeFileSync(
|
|
161
|
-
path.resolve(o.context, o.outputPath, 'sitemap.xml'),
|
|
162
|
-
sitemap,
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// TODO: Once all assets are named by hashes, we probably don't need build
|
|
168
|
-
// info anymore beside the key, which can be merged into stats object?
|
|
169
|
-
// On the other hand, it is still handy to have to pass around the build
|
|
170
|
-
// timestamp, and any other similar information to the actual app, so it
|
|
171
|
-
// can be used in some scenarious.
|
|
172
|
-
let buildInfo;
|
|
173
|
-
const buildInfoUrl = path.resolve(o.context, '.build-info');
|
|
174
|
-
|
|
175
|
-
if (o.keepBuildInfo) {
|
|
176
|
-
// If "true" - attempt to load from the filesystem.
|
|
177
|
-
if (o.keepBuildInfo === true) {
|
|
178
|
-
if (fs.existsSync(buildInfoUrl)) {
|
|
179
|
-
buildInfo = JSON.parse(fs.readFileSync(buildInfoUrl));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Otherwise we assume .keepBuildInfo value itself is the build info object
|
|
183
|
-
// to use in the build.
|
|
184
|
-
} else buildInfo = o.keepBuildInfo;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Even if "keepBuildInfo" option was provided, we still generate a new
|
|
188
|
-
// build info object in case nothing could be loaded.
|
|
189
|
-
if (!buildInfo) {
|
|
190
|
-
buildInfo = Object.freeze({
|
|
191
|
-
/* A random 32-bit key, that can be used for encryption. */
|
|
192
|
-
key: forge.random.getBytesSync(32),
|
|
193
|
-
|
|
194
|
-
/* Public path used during build. */
|
|
195
|
-
publicPath: o.publicPath,
|
|
196
|
-
|
|
197
|
-
/* `true` if client-side code should setup a service worker. */
|
|
198
|
-
useServiceWorker: Boolean(o.workbox),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// If not opted-out, we write the build info to the filesystem. We also attach
|
|
203
|
-
// it to the factory function itself, so it can be easily accessed right after
|
|
204
|
-
// the factory call in testing scenarios.
|
|
205
|
-
if (!o.dontEmitBuildInfo) {
|
|
206
|
-
// Note: this is needed if "fs" option is provided, to ensure the factory
|
|
207
|
-
// does not crash if the folder is not created in that filesystem.
|
|
208
|
-
fs.mkdirSync(o.context, { recursive: true });
|
|
209
|
-
|
|
210
|
-
fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/* Entry points normalization. */
|
|
214
|
-
const entry = [
|
|
215
|
-
'core-js/stable',
|
|
216
|
-
'regenerator-runtime/runtime',
|
|
217
|
-
'nodelist-foreach-polyfill',
|
|
218
|
-
...Array.isArray(o.entry) ? o.entry : [o.entry],
|
|
219
|
-
];
|
|
220
|
-
|
|
221
|
-
const plugins = [
|
|
222
|
-
new DefinePlugin({ BUILD_INFO: JSON.stringify(buildInfo) }),
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
if (!ops.dontUseProgressPlugin) plugins.push(new ProgressPlugin());
|
|
226
|
-
|
|
227
|
-
/* Adds InjectManifest plugin from WorkBox, if opted to. */
|
|
228
|
-
if (o.workbox) {
|
|
229
|
-
if (!isObject(o.workbox)) o.workbox = {};
|
|
230
|
-
plugins.push(new WorkboxPlugin.InjectManifest({
|
|
231
|
-
swSrc: path.resolve(__dirname, '../workbox/default.js'),
|
|
232
|
-
...o.workbox,
|
|
233
|
-
swDest: '__service-worker.js',
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
context: o.context,
|
|
239
|
-
entry,
|
|
240
|
-
node: {
|
|
241
|
-
__dirname: true,
|
|
242
|
-
},
|
|
243
|
-
mode: o.mode,
|
|
244
|
-
output: {
|
|
245
|
-
chunkFilename: '[contenthash].js',
|
|
246
|
-
filename: '[contenthash].js',
|
|
247
|
-
path: path.resolve(__dirname, o.context, o.outputPath),
|
|
248
|
-
publicPath: `${o.publicPath}/`,
|
|
249
|
-
},
|
|
250
|
-
plugins,
|
|
251
|
-
resolve: {
|
|
252
|
-
alias: {
|
|
253
|
-
/* Aliases to JS an JSX files are handled by Babel. */
|
|
254
|
-
assets: path.resolve(o.context, 'src/assets'),
|
|
255
|
-
components: path.resolve(o.context, 'src/shared/components'),
|
|
256
|
-
fonts: path.resolve(o.context, 'src/assets/fonts'),
|
|
257
|
-
styles: path.resolve(o.context, 'src/styles'),
|
|
258
|
-
},
|
|
259
|
-
extensions: ['.js', '.json', '.jsx', '.scss'],
|
|
260
|
-
symlinks: false,
|
|
261
|
-
},
|
|
262
|
-
module: {
|
|
263
|
-
rules: [{
|
|
264
|
-
/* Loads font resources from "src/assets/fonts" folder. */
|
|
265
|
-
test: /\.(eot|otf|svg|ttf|woff2?)$/,
|
|
266
|
-
include: [
|
|
267
|
-
/node_modules/,
|
|
268
|
-
/src[/\\]assets[/\\]fonts/,
|
|
269
|
-
],
|
|
270
|
-
type: 'asset/resource',
|
|
271
|
-
generator: {
|
|
272
|
-
filename: 'fonts/[contenthash][ext][query]',
|
|
273
|
-
},
|
|
274
|
-
}, {
|
|
275
|
-
/* Loads JS and JSX moudles, and inlines SVG assets. */
|
|
276
|
-
test: /\.(jsx?|svg)$/,
|
|
277
|
-
exclude: [/node_modules/],
|
|
278
|
-
loader: 'babel-loader',
|
|
279
|
-
options: {
|
|
280
|
-
babelrc: false,
|
|
281
|
-
configFile: false,
|
|
282
|
-
envName: o.babelEnv,
|
|
283
|
-
presets: ['@dr.pogodin/react-utils/config/babel/webpack'],
|
|
284
|
-
...o.babelLoaderOptions,
|
|
285
|
-
},
|
|
286
|
-
}, {
|
|
287
|
-
/* Loads image assets. */
|
|
288
|
-
test: /\.(gif|jpe?g|png)$/,
|
|
289
|
-
type: 'asset/resource',
|
|
290
|
-
generator: {
|
|
291
|
-
filename: 'images/[contenthash][ext][query]',
|
|
292
|
-
},
|
|
293
|
-
}, {
|
|
294
|
-
/* Loads SCSS stylesheets. */
|
|
295
|
-
test: /\.scss$/,
|
|
296
|
-
use: [
|
|
297
|
-
MiniCssExtractPlugin.loader, {
|
|
298
|
-
loader: 'css-loader',
|
|
299
|
-
options: {
|
|
300
|
-
modules: {
|
|
301
|
-
getLocalIdent,
|
|
302
|
-
localIdentName: o.cssLocalIdent,
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
}, {
|
|
306
|
-
loader: 'postcss-loader',
|
|
307
|
-
options: {
|
|
308
|
-
postcssOptions: {
|
|
309
|
-
plugins: [autoprefixer],
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
}, 'resolve-url-loader', {
|
|
313
|
-
loader: 'sass-loader',
|
|
314
|
-
options: {
|
|
315
|
-
sourceMap: true,
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
],
|
|
319
|
-
}, {
|
|
320
|
-
/* Loads CSS stylesheets. It is assumed that CSS stylesheets come only
|
|
321
|
-
* from dependencies, as we use SCSS inside our own code. */
|
|
322
|
-
test: /\.css$/,
|
|
323
|
-
use: [
|
|
324
|
-
MiniCssExtractPlugin.loader,
|
|
325
|
-
'css-loader',
|
|
326
|
-
],
|
|
327
|
-
}],
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
};
|