@dr.pogodin/react-utils 1.26.0 → 1.26.1

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.
@@ -0,0 +1,17 @@
1
+ import { type BabelCompilerI, type ConfigT, type OptionsT as WebpackConfigOptionsT } from './webpack';
2
+ type OptionsT = WebpackConfigOptionsT & {
3
+ baseAssetsOutputPath?: string;
4
+ };
5
+ /**
6
+ * Generates Babel config for NodeJS compilation and server-side execution.
7
+ * @param babel Babel compiler instance.
8
+ * @param [ops] Preset options. It supports all options accepted by
9
+ * the underlying {@link module:babel/webpack preset for Webpack}, but it
10
+ * overrides `targets` option by `current node` value, and also accepts
11
+ * the following additional options:
12
+ * @param [ops.baseAssetsOutputPath] Path prefix for emitted image
13
+ * assets.
14
+ * @return Generated config.
15
+ */
16
+ export default function getConfig(babel: BabelCompilerI, ops?: OptionsT): ConfigT;
17
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const lodash_1 = require("lodash");
28
+ const webpack_1 = __importStar(require("./webpack"));
29
+ /**
30
+ * Creates a new base config.
31
+ * @param {object} babel Babel compiler.
32
+ * @param {object} [options] It supports all options of
33
+ * {@link module:babel/webpack.getPreset babel/webpack's getPreset()},
34
+ * but it overrides `targets` option with `current node` value, and further
35
+ * accepts the following:
36
+ * @param {string} [options.baseAssetsOutputPath] Path prefix for emitted
37
+ * image assets.
38
+ * @return {object} Created config object.
39
+ * @ignore
40
+ */
41
+ function newBase(babel, options = {}) {
42
+ const config = (0, webpack_1.default)(babel, Object.assign(Object.assign({}, options), { targets: 'current node' }));
43
+ const baseAssetsOutputPath = options.baseAssetsOutputPath || '';
44
+ config.plugins.push(['@dr.pogodin/transform-assets', {
45
+ extensions: ['gif', 'jpeg', 'jpg', 'png'],
46
+ name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
47
+ }]);
48
+ const moduleResolverPluginOps = (config.plugins.find((x) => x[0] === 'module-resolver'))[1];
49
+ moduleResolverPluginOps.transformFunctions = [
50
+ 'requireWeak',
51
+ 'resolveWeak',
52
+ 'webpack.requireWeak',
53
+ 'webpack.resolveWeak',
54
+ ];
55
+ if (babel.env() === webpack_1.ENVIRONMENTS.DEV) {
56
+ (0, lodash_1.pull)(config.plugins, 'react-refresh/babel');
57
+ }
58
+ return config;
59
+ }
60
+ /**
61
+ * Updates given `config` with styling ((S)CSS-related) setup.
62
+ *
63
+ * **Beware:** It mutates `config`.
64
+ *
65
+ * @param {object} config
66
+ * @return {object} Returns mutated config for chaining.
67
+ * @ignore
68
+ */
69
+ function addStyling(config) {
70
+ const cssModulesOps = config.plugins.find(([name]) => name === '@dr.pogodin/react-css-modules')[1];
71
+ cssModulesOps.replaceImport = true;
72
+ return config;
73
+ }
74
+ /**
75
+ * Generates Babel config for NodeJS compilation and server-side execution.
76
+ * @param babel Babel compiler instance.
77
+ * @param [ops] Preset options. It supports all options accepted by
78
+ * the underlying {@link module:babel/webpack preset for Webpack}, but it
79
+ * overrides `targets` option by `current node` value, and also accepts
80
+ * the following additional options:
81
+ * @param [ops.baseAssetsOutputPath] Path prefix for emitted image
82
+ * assets.
83
+ * @return Generated config.
84
+ */
85
+ function getConfig(babel, ops = {}) {
86
+ const config = newBase(babel, ops);
87
+ if (!ops.noStyling)
88
+ addStyling(config);
89
+ return config;
90
+ }
91
+ exports.default = getConfig;
@@ -0,0 +1,40 @@
1
+ export interface BabelCompilerI {
2
+ env: () => string;
3
+ }
4
+ /**
5
+ * Supported Babel environments.
6
+ */
7
+ export declare enum ENVIRONMENTS {
8
+ DEV = "development",
9
+ PROD = "production",
10
+ TEST = "test"
11
+ }
12
+ export interface PresetOrPluginOptionsI {
13
+ }
14
+ type PresetOrPluginT = string | [string, PresetOrPluginOptionsI];
15
+ export type ConfigT = {
16
+ presets: PresetOrPluginT[];
17
+ plugins: PresetOrPluginT[];
18
+ };
19
+ export type OptionsT = {
20
+ noRR?: boolean;
21
+ noStyling?: boolean;
22
+ targets?: string | string[] | {
23
+ [key: string]: string;
24
+ };
25
+ typescript?: boolean;
26
+ };
27
+ /**
28
+ * Generates Babel preset for Webpack.
29
+ * @param babel Babel compiler.
30
+ * @param [ops] Preset options.
31
+ * @param [ops.noRR] If truthy `react-refresh/babel` plugin is not
32
+ * included into config, no matter the environment.
33
+ * @param [ops.noStyling] If truthy all setup related to styling
34
+ * ((S)CSS processing) will be skipped.
35
+ * @param [ops.targets=defaults] Targets for
36
+ * `@babel/preset-env`.
37
+ * @return Generated config.
38
+ */
39
+ export default function getPreset(babel: BabelCompilerI, ops?: OptionsT): ConfigT;
40
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENTS = void 0;
4
+ const { generateScopedNameFactory, } = require('@dr.pogodin/babel-plugin-react-css-modules/utils');
5
+ const generateScopedNameDev = generateScopedNameFactory('[package]___[path][name]___[local]___[hash:base64:6]');
6
+ const generateScopedNameProd = generateScopedNameFactory('[hash:base64:6]');
7
+ /**
8
+ * Supported Babel environments.
9
+ */
10
+ var ENVIRONMENTS;
11
+ (function (ENVIRONMENTS) {
12
+ ENVIRONMENTS["DEV"] = "development";
13
+ ENVIRONMENTS["PROD"] = "production";
14
+ ENVIRONMENTS["TEST"] = "test";
15
+ })(ENVIRONMENTS || (exports.ENVIRONMENTS = ENVIRONMENTS = {}));
16
+ /**
17
+ * Creates a new base config.
18
+ * @param [options] Base config options.
19
+ * @return Generated config.
20
+ */
21
+ function newBaseConfig(options) {
22
+ return {
23
+ presets: [
24
+ // Chrome 69 is the browser for Android API 28.
25
+ ['@babel/env', { targets: options.targets || 'defaults or chrome >= 69' }],
26
+ // TODO: Starting from Babel 8, "automatic" will be the default runtime,
27
+ // thus once upgraded to Babel 8, runtime should be removed from
28
+ // @babel/react options below.
29
+ ['@babel/react', { runtime: 'automatic' }],
30
+ '@dr.pogodin/babel-preset-svgr',
31
+ ],
32
+ plugins: [
33
+ ['module-resolver', {
34
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
35
+ root: [
36
+ './src/shared',
37
+ './src',
38
+ ],
39
+ }],
40
+ '@babel/transform-runtime',
41
+ ],
42
+ };
43
+ }
44
+ /**
45
+ * Updates given `config` with styling ((S)CSS-related) setup.
46
+ *
47
+ * **Beware:** It mutates `config`.
48
+ *
49
+ * @param {object} config
50
+ * @param {string} env Target environment: `development` or `production`.
51
+ * @return {object} Returns mutated config for chaining.
52
+ * @ignore
53
+ */
54
+ function addStyling(config, env) {
55
+ const cssModulesOps = {
56
+ autoResolveMultipleImports: true,
57
+ filetypes: {
58
+ '.scss': { syntax: 'postcss-scss' },
59
+ },
60
+ };
61
+ config.plugins.push(['@dr.pogodin/react-css-modules', cssModulesOps]);
62
+ switch (env) {
63
+ case ENVIRONMENTS.DEV:
64
+ case ENVIRONMENTS.TEST:
65
+ cssModulesOps.generateScopedName = generateScopedNameDev;
66
+ break;
67
+ case ENVIRONMENTS.PROD:
68
+ cssModulesOps.generateScopedName = generateScopedNameProd;
69
+ break;
70
+ default:
71
+ }
72
+ return config;
73
+ }
74
+ /**
75
+ * Generates Babel preset for Webpack.
76
+ * @param babel Babel compiler.
77
+ * @param [ops] Preset options.
78
+ * @param [ops.noRR] If truthy `react-refresh/babel` plugin is not
79
+ * included into config, no matter the environment.
80
+ * @param [ops.noStyling] If truthy all setup related to styling
81
+ * ((S)CSS processing) will be skipped.
82
+ * @param [ops.targets=defaults] Targets for
83
+ * `@babel/preset-env`.
84
+ * @return Generated config.
85
+ */
86
+ function getPreset(babel, ops = {}) {
87
+ const env = babel.env();
88
+ const res = newBaseConfig(ops);
89
+ if (!ops.noStyling)
90
+ addStyling(res, env);
91
+ if (env === ENVIRONMENTS.DEV && !ops.noRR) {
92
+ res.plugins.push('react-refresh/babel');
93
+ }
94
+ // Conditional to not require non-TypeScript projects to install TypeScript-
95
+ // specific dependencies for build process.
96
+ if (ops.typescript) {
97
+ res.presets.push(['@babel/typescript', {
98
+ // This ensures TypeScript compilation does not remove "unused" imports,
99
+ // as in most cases it considers assets (e.g. stylesheet) imports as
100
+ // unused, while other steps of our build process rely on them
101
+ // (e.g. @dr.pogodin/react-css-modules plugin).
102
+ onlyRemoveTypeImports: true,
103
+ }]);
104
+ }
105
+ return res;
106
+ }
107
+ exports.default = getPreset;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @category Configs
3
+ * @module webpack/app-base
4
+ * @desc
5
+ * Base [Webpack](https://webpack.js.org/) configuration for apps.
6
+ */
7
+ /// <reference types="node" />
8
+ import nodeFs from 'fs';
9
+ import { type Configuration } from 'webpack';
10
+ export type BuildInfoT = {
11
+ key: string;
12
+ publicPath: string;
13
+ timestamp: string;
14
+ useServiceWorker: boolean;
15
+ };
16
+ export type OptionsT = {
17
+ babelEnv: string;
18
+ babelLoaderOptions?: object;
19
+ context: string;
20
+ cssLocalIdent?: string;
21
+ dontEmitBuildInfo?: boolean;
22
+ dontUseProgressPlugin?: boolean;
23
+ entry: string | string[];
24
+ fs?: typeof nodeFs;
25
+ keepBuildInfo?: boolean | BuildInfoT;
26
+ mode: 'development' | 'none' | 'production';
27
+ outputPath?: string;
28
+ publicPath?: string;
29
+ sitemap?: string;
30
+ typescript?: boolean;
31
+ workbox?: boolean | object;
32
+ };
33
+ /**
34
+ * Creates a new Webpack config object, and performs some auxiliary operations
35
+ * on the way.
36
+ * @param {object} ops Configuration params. This allows to modify some
37
+ * frequently changed options in a convenient way, without a need to manipulate
38
+ * directly with the created config object.
39
+ * @param {string} ops.babelEnv Babel environment to use for the Babel
40
+ * compilation step.
41
+ * @param {object} [ops.babelLoaderOptions] Overrides for default Babel options
42
+ * of JSX and SVG files loader.
43
+ * @param ops.context Base URL for resolution of relative config paths.
44
+ * @param {string} [ops.cssLocalIdent=hash:base64:6] The template for
45
+ * CSS classnames generation by the Webpack's `css-loader`; it is passed into
46
+ * the `localIdentName` param of the loader. It should match the corresponding
47
+ * setting in the Babel config.
48
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
49
+ * be created at the disk during the compilation.
50
+ * @param [ops.dontUseProgressPlugin] Set to not include progress
51
+ * plugin.
52
+ * @param {string|string[]} ops.entry Entry points for "main" chunk. The config
53
+ * will prepend them by some necessary polyfills, e.g.:
54
+ * ([babel-polyfill](https://babeljs.io/docs/usage/polyfill/),
55
+ * [nodelist-foreach-polyfill](https://www.npmjs.com/package/nodelist-foreach-polyfill)).
56
+ * @param {boolean|object} ops.workbox If evaluates to a truthy value,
57
+ * [Workbox's InjectManifest plugin](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#injectmanifest_plugin)
58
+ * is added to the array of Webpack plugins, to generate service worker for
59
+ * browser. If the value is an object, it is merged into the options passed
60
+ * into the plugin, otherwise default options are used:
61
+ * ```json
62
+ * {
63
+ * "importWorkboxFrom": "local",
64
+ * "swSrc": "@dr.pogodin/react-utils/config/workbox/default.js",
65
+ * "swDest": "__service-worker.js"
66
+ * }
67
+ * ```
68
+ * If service worker is generated by this option, it will be automatically
69
+ * initiated at the client side by the standard
70
+ * [client-side initialization script](docs/client.md)
71
+ * provided by **@dr.pogodin/react-utils**. Note that `swDest`'s value cannot be
72
+ * overriden by config options provided via `workbox` object.
73
+ * @param {object} [ops.fs] Filesystem to use instead of the Node's FS.
74
+ * @param {boolean|object} [ops.keepBuildInfo] If `true` and a `.build-info`
75
+ * file from a previous build exists in the context directory, it will be
76
+ * loaded and used, rather than re-generated by the config factory. It allows
77
+ * to re-create the Webpack config during a server launch without re-generation
78
+ * of the build info file created during a previous build (and thus bundled
79
+ * into the frontend bundle). If an object is provided, it will be used as
80
+ * the build info, instead of trying to load it from the filesystem. This
81
+ * feature is intended for testing context.
82
+ * @param {string} ops.mode
83
+ * [Webpack mode](https://webpack.js.org/concepts/mode/).
84
+ * @param {string} [ops.outputPath=build] Optional. Output path for the build.
85
+ * @param {string} ops.publicPath Base URL for the output of the build assets.
86
+ * @param {string} [ops.sitemap] The path to JS or JSON config for sitemap.
87
+ * It can be relative to the context, and can be a factory, which returns
88
+ * the config. The config should be compatible with
89
+ * [`sitemap`](https://www.npmjs.com/package/sitemap) library, and if
90
+ * provided the Webpack config factory will use it to gererate `sitemap.xml`
91
+ * file in the output folder, and then serve it from the app root.
92
+ * @return The generated config will opt to:
93
+ * - Bundle the font assets (EOF, OTF, SVG, TTF, WOFF, WOFF2 files from
94
+ * the `src/assets/fonts` folder of your source code will be bundled
95
+ * and output into the `[PUBLIC_PATH]/fonts` folder);
96
+ * - Bundle image assets (GIF, JPEG, JPG, PNG files from any folder of
97
+ * your source code will be bundled and output into the
98
+ * `[PUBLIC_PATH]/images` folder);
99
+ * - Bundle SCSS files from any folder of your source code, beside
100
+ * `node_modules` and its subfolders. The files will be compiled,
101
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
102
+ * bundles;
103
+ * - Bundle CSS files from any folder of your code. The files will be
104
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
105
+ * bundles;
106
+ * - Bundle JS, JSX, and SVG files; they will be compiled into the
107
+ * `[PUBLIC_PATH]/[CHUNK_NAME].js` bundles, using the Babel environment
108
+ * specified in the factory options, and
109
+ * [`config/babel/webpack`](./babel-config.js#webpack) config.
110
+ *
111
+ * - The following path aliases will be automatically set:
112
+ * - **`assets`** for `[CONTEXT]/src/assets`;
113
+ * - **`components`** for `[CONTEXT]/src/shared/components`;
114
+ * - **`fonts`** for `[CONTEXT]/src/assets/fonts`;
115
+ * - **`styles`** for `[CONTEXT]/src/styles`.
116
+ *
117
+ * Also `resolve.symlinks` Webpack option is set to *false* to avoid problems
118
+ * with resolution of assets from packages linked with `npm link`.
119
+ *
120
+ * - The following global variables will be emulated inside the output
121
+ * JS bundle:
122
+ * - **`BUILD_RNDKEY`** &mdash; A random 32 bit key that can be used
123
+ * for encryption, it is set just as a global variable accessible in
124
+ * the code;
125
+ * - **`BUILD_TIMESTAMP`** &mdash; UTC timestamp of the beginning of
126
+ * the build;
127
+ * - **`FRONT_END`** &mdash; It will be set *true* inside the bundle,
128
+ * so that shared code can use it to determine that it is executed
129
+ * at the client side.
130
+ *
131
+ * - It also opts to polyfill the `__dirname` global variable,
132
+ * and to ignore imports of the `fs` Node package;
133
+ *
134
+ * - Also, it will store to the disk (re-writes if exists) the file
135
+ * `[CONTEXT]/.build-info` which will contain a stringified JSON
136
+ * object with the following fields:
137
+ * - **`rndkey`** &mdash; The value set for `BUILD_RNDKEY`;
138
+ * - **`timestamp`** &mdash; The value set for `BUILD_TIMESTAMP`.
139
+ */
140
+ export default function configFactory(ops: OptionsT): Configuration;
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ /**
3
+ * @category Configs
4
+ * @module webpack/app-base
5
+ * @desc
6
+ * Base [Webpack](https://webpack.js.org/) configuration for apps.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const sitemap_1 = __importDefault(require("sitemap"));
15
+ const lodash_1 = require("lodash");
16
+ const autoprefixer_1 = __importDefault(require("autoprefixer"));
17
+ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
18
+ const node_forge_1 = __importDefault(require("node-forge"));
19
+ const webpack_1 = require("webpack");
20
+ const workbox_webpack_plugin_1 = __importDefault(require("workbox-webpack-plugin"));
21
+ const utils_1 = require("@dr.pogodin/babel-plugin-react-css-modules/utils");
22
+ /**
23
+ * Creates a new Webpack config object, and performs some auxiliary operations
24
+ * on the way.
25
+ * @param {object} ops Configuration params. This allows to modify some
26
+ * frequently changed options in a convenient way, without a need to manipulate
27
+ * directly with the created config object.
28
+ * @param {string} ops.babelEnv Babel environment to use for the Babel
29
+ * compilation step.
30
+ * @param {object} [ops.babelLoaderOptions] Overrides for default Babel options
31
+ * of JSX and SVG files loader.
32
+ * @param ops.context Base URL for resolution of relative config paths.
33
+ * @param {string} [ops.cssLocalIdent=hash:base64:6] The template for
34
+ * CSS classnames generation by the Webpack's `css-loader`; it is passed into
35
+ * the `localIdentName` param of the loader. It should match the corresponding
36
+ * setting in the Babel config.
37
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
38
+ * be created at the disk during the compilation.
39
+ * @param [ops.dontUseProgressPlugin] Set to not include progress
40
+ * plugin.
41
+ * @param {string|string[]} ops.entry Entry points for "main" chunk. The config
42
+ * will prepend them by some necessary polyfills, e.g.:
43
+ * ([babel-polyfill](https://babeljs.io/docs/usage/polyfill/),
44
+ * [nodelist-foreach-polyfill](https://www.npmjs.com/package/nodelist-foreach-polyfill)).
45
+ * @param {boolean|object} ops.workbox If evaluates to a truthy value,
46
+ * [Workbox's InjectManifest plugin](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#injectmanifest_plugin)
47
+ * is added to the array of Webpack plugins, to generate service worker for
48
+ * browser. If the value is an object, it is merged into the options passed
49
+ * into the plugin, otherwise default options are used:
50
+ * ```json
51
+ * {
52
+ * "importWorkboxFrom": "local",
53
+ * "swSrc": "@dr.pogodin/react-utils/config/workbox/default.js",
54
+ * "swDest": "__service-worker.js"
55
+ * }
56
+ * ```
57
+ * If service worker is generated by this option, it will be automatically
58
+ * initiated at the client side by the standard
59
+ * [client-side initialization script](docs/client.md)
60
+ * provided by **@dr.pogodin/react-utils**. Note that `swDest`'s value cannot be
61
+ * overriden by config options provided via `workbox` object.
62
+ * @param {object} [ops.fs] Filesystem to use instead of the Node's FS.
63
+ * @param {boolean|object} [ops.keepBuildInfo] If `true` and a `.build-info`
64
+ * file from a previous build exists in the context directory, it will be
65
+ * loaded and used, rather than re-generated by the config factory. It allows
66
+ * to re-create the Webpack config during a server launch without re-generation
67
+ * of the build info file created during a previous build (and thus bundled
68
+ * into the frontend bundle). If an object is provided, it will be used as
69
+ * the build info, instead of trying to load it from the filesystem. This
70
+ * feature is intended for testing context.
71
+ * @param {string} ops.mode
72
+ * [Webpack mode](https://webpack.js.org/concepts/mode/).
73
+ * @param {string} [ops.outputPath=build] Optional. Output path for the build.
74
+ * @param {string} ops.publicPath Base URL for the output of the build assets.
75
+ * @param {string} [ops.sitemap] The path to JS or JSON config for sitemap.
76
+ * It can be relative to the context, and can be a factory, which returns
77
+ * the config. The config should be compatible with
78
+ * [`sitemap`](https://www.npmjs.com/package/sitemap) library, and if
79
+ * provided the Webpack config factory will use it to gererate `sitemap.xml`
80
+ * file in the output folder, and then serve it from the app root.
81
+ * @return The generated config will opt to:
82
+ * - Bundle the font assets (EOF, OTF, SVG, TTF, WOFF, WOFF2 files from
83
+ * the `src/assets/fonts` folder of your source code will be bundled
84
+ * and output into the `[PUBLIC_PATH]/fonts` folder);
85
+ * - Bundle image assets (GIF, JPEG, JPG, PNG files from any folder of
86
+ * your source code will be bundled and output into the
87
+ * `[PUBLIC_PATH]/images` folder);
88
+ * - Bundle SCSS files from any folder of your source code, beside
89
+ * `node_modules` and its subfolders. The files will be compiled,
90
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
91
+ * bundles;
92
+ * - Bundle CSS files from any folder of your code. The files will be
93
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
94
+ * bundles;
95
+ * - Bundle JS, JSX, and SVG files; they will be compiled into the
96
+ * `[PUBLIC_PATH]/[CHUNK_NAME].js` bundles, using the Babel environment
97
+ * specified in the factory options, and
98
+ * [`config/babel/webpack`](./babel-config.js#webpack) config.
99
+ *
100
+ * - The following path aliases will be automatically set:
101
+ * - **`assets`** for `[CONTEXT]/src/assets`;
102
+ * - **`components`** for `[CONTEXT]/src/shared/components`;
103
+ * - **`fonts`** for `[CONTEXT]/src/assets/fonts`;
104
+ * - **`styles`** for `[CONTEXT]/src/styles`.
105
+ *
106
+ * Also `resolve.symlinks` Webpack option is set to *false* to avoid problems
107
+ * with resolution of assets from packages linked with `npm link`.
108
+ *
109
+ * - The following global variables will be emulated inside the output
110
+ * JS bundle:
111
+ * - **`BUILD_RNDKEY`** &mdash; A random 32 bit key that can be used
112
+ * for encryption, it is set just as a global variable accessible in
113
+ * the code;
114
+ * - **`BUILD_TIMESTAMP`** &mdash; UTC timestamp of the beginning of
115
+ * the build;
116
+ * - **`FRONT_END`** &mdash; It will be set *true* inside the bundle,
117
+ * so that shared code can use it to determine that it is executed
118
+ * at the client side.
119
+ *
120
+ * - It also opts to polyfill the `__dirname` global variable,
121
+ * and to ignore imports of the `fs` Node package;
122
+ *
123
+ * - Also, it will store to the disk (re-writes if exists) the file
124
+ * `[CONTEXT]/.build-info` which will contain a stringified JSON
125
+ * object with the following fields:
126
+ * - **`rndkey`** &mdash; The value set for `BUILD_RNDKEY`;
127
+ * - **`timestamp`** &mdash; The value set for `BUILD_TIMESTAMP`.
128
+ */
129
+ function configFactory(ops) {
130
+ const o = (0, lodash_1.defaults)((0, lodash_1.clone)(ops), {
131
+ babelLoaderOptions: {},
132
+ cssLocalIdent: '[hash:base64:6]',
133
+ outputPath: 'build/web-public',
134
+ publicPath: '',
135
+ });
136
+ const fs = ops.fs || fs_1.default;
137
+ /* TODO: This works in practice, but being async and not awaited it is a bad
138
+ * pattern. */
139
+ if (o.sitemap) {
140
+ const sitemapUrl = path_1.default.resolve(o.context, o.sitemap);
141
+ /* eslint-disable global-require, import/no-dynamic-require */
142
+ let source = require(sitemapUrl);
143
+ if ((0, lodash_1.isFunction)(source))
144
+ source = source();
145
+ /* eslint-enable global-require, import/no-dynamic-require */
146
+ const sm = new sitemap_1.default.SitemapStream();
147
+ source.forEach((item) => sm.write(item));
148
+ sm.end();
149
+ sitemap_1.default.streamToPromise(sm).then((sitemap) => {
150
+ const outUrl = path_1.default.resolve(o.context, o.outputPath);
151
+ if (!fs.existsSync(outUrl))
152
+ fs.mkdirSync(outUrl);
153
+ fs.writeFileSync(path_1.default.resolve(o.context, o.outputPath, 'sitemap.xml'), sitemap);
154
+ });
155
+ }
156
+ // TODO: Once all assets are named by hashes, we probably don't need build
157
+ // info anymore beside the key, which can be merged into stats object?
158
+ // On the other hand, it is still handy to have to pass around the build
159
+ // timestamp, and any other similar information to the actual app, so it
160
+ // can be used in some scenarious.
161
+ let buildInfo;
162
+ const buildInfoUrl = path_1.default.resolve(o.context, '.build-info');
163
+ if (o.keepBuildInfo) {
164
+ // If "true" - attempt to load from the filesystem.
165
+ if (o.keepBuildInfo === true) {
166
+ if (fs.existsSync(buildInfoUrl)) {
167
+ buildInfo = JSON.parse(fs.readFileSync(buildInfoUrl, 'utf8'));
168
+ }
169
+ // Otherwise we assume .keepBuildInfo value itself is the build info object
170
+ // to use in the build.
171
+ }
172
+ else
173
+ buildInfo = o.keepBuildInfo;
174
+ }
175
+ // Even if "keepBuildInfo" option was provided, we still generate a new
176
+ // build info object in case nothing could be loaded.
177
+ if (!buildInfo) {
178
+ buildInfo = Object.freeze({
179
+ /* A random 32-bit key, that can be used for encryption. */
180
+ key: node_forge_1.default.random.getBytesSync(32),
181
+ /* Public path used during build. */
182
+ publicPath: o.publicPath,
183
+ /* `true` if client-side code should setup a service worker. */
184
+ useServiceWorker: Boolean(o.workbox),
185
+ // Build timestamp.
186
+ timestamp: new Date().toISOString(),
187
+ });
188
+ }
189
+ // If not opted-out, we write the build info to the filesystem. We also attach
190
+ // it to the factory function itself, so it can be easily accessed right after
191
+ // the factory call in testing scenarios.
192
+ if (!o.dontEmitBuildInfo) {
193
+ // Note: this is needed if "fs" option is provided, to ensure the factory
194
+ // does not crash if the folder is not created in that filesystem.
195
+ fs.mkdirSync(o.context, { recursive: true });
196
+ fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
197
+ }
198
+ /* Entry points normalization. */
199
+ const entry = [
200
+ 'core-js/stable',
201
+ 'regenerator-runtime/runtime',
202
+ 'nodelist-foreach-polyfill',
203
+ ...Array.isArray(o.entry) ? o.entry : [o.entry],
204
+ ];
205
+ const plugins = [
206
+ new webpack_1.DefinePlugin({ BUILD_INFO: JSON.stringify(buildInfo) }),
207
+ ];
208
+ if (!ops.dontUseProgressPlugin)
209
+ plugins.push(new webpack_1.ProgressPlugin());
210
+ /* Adds InjectManifest plugin from WorkBox, if opted to. */
211
+ if (o.workbox) {
212
+ if (!(0, lodash_1.isObject)(o.workbox))
213
+ o.workbox = {};
214
+ plugins.push(new workbox_webpack_plugin_1.default.InjectManifest(Object.assign(Object.assign({ swSrc: path_1.default.resolve(__dirname, '../workbox/default.js') }, o.workbox), { swDest: '__service-worker.js' })));
215
+ }
216
+ return {
217
+ context: o.context,
218
+ entry,
219
+ node: {
220
+ __dirname: true,
221
+ },
222
+ mode: o.mode,
223
+ output: {
224
+ chunkFilename: '[contenthash].js',
225
+ filename: '[contenthash].js',
226
+ path: path_1.default.resolve(__dirname, o.context, o.outputPath),
227
+ publicPath: `${o.publicPath}/`,
228
+ },
229
+ plugins,
230
+ resolve: {
231
+ alias: {
232
+ // Aliases to JS an JSX files are handled by Babel.
233
+ assets: path_1.default.resolve(o.context, 'src/assets'),
234
+ components: path_1.default.resolve(o.context, 'src/shared/components'),
235
+ fonts: path_1.default.resolve(o.context, 'src/assets/fonts'),
236
+ styles: path_1.default.resolve(o.context, 'src/styles'),
237
+ },
238
+ extensions: [
239
+ '.ts',
240
+ '.tsx',
241
+ '.js',
242
+ '.jsx',
243
+ '.json',
244
+ '.scss',
245
+ ],
246
+ symlinks: false,
247
+ },
248
+ module: {
249
+ rules: [{
250
+ /* Loads font resources from "src/assets/fonts" folder. */
251
+ test: /\.(eot|otf|svg|ttf|woff2?)$/,
252
+ include: [
253
+ /node_modules/,
254
+ /src[/\\]assets[/\\]fonts/,
255
+ ],
256
+ type: 'asset/resource',
257
+ generator: {
258
+ filename: 'fonts/[contenthash][ext][query]',
259
+ },
260
+ }, {
261
+ /* Loads JS and JSX moudles, and inlines SVG assets. */
262
+ test: ops.typescript ? /\.((j|t)sx?|svg)$/ : /\.(jsx?|svg)$/,
263
+ exclude: [/node_modules/],
264
+ loader: 'babel-loader',
265
+ options: Object.assign({ babelrc: false, configFile: false, envName: o.babelEnv, presets: [['@dr.pogodin/react-utils/config/babel/webpack', {
266
+ typescript: ops.typescript,
267
+ }]] }, o.babelLoaderOptions),
268
+ }, {
269
+ /* Loads image assets. */
270
+ test: /\.(gif|jpe?g|png)$/,
271
+ type: 'asset/resource',
272
+ generator: {
273
+ filename: 'images/[contenthash][ext][query]',
274
+ },
275
+ }, {
276
+ /* Loads SCSS stylesheets. */
277
+ test: /\.scss$/,
278
+ use: [
279
+ mini_css_extract_plugin_1.default.loader, {
280
+ loader: 'css-loader',
281
+ options: {
282
+ modules: {
283
+ getLocalIdent: utils_1.getLocalIdent,
284
+ localIdentName: o.cssLocalIdent,
285
+ },
286
+ },
287
+ }, {
288
+ loader: 'postcss-loader',
289
+ options: {
290
+ postcssOptions: {
291
+ plugins: [autoprefixer_1.default],
292
+ },
293
+ },
294
+ }, 'resolve-url-loader', {
295
+ loader: 'sass-loader',
296
+ options: {
297
+ sourceMap: true,
298
+ },
299
+ },
300
+ ],
301
+ }, {
302
+ /* Loads CSS stylesheets. It is assumed that CSS stylesheets come only
303
+ * from dependencies, as we use SCSS inside our own code. */
304
+ test: /\.css$/,
305
+ use: [
306
+ mini_css_extract_plugin_1.default.loader,
307
+ 'css-loader',
308
+ ],
309
+ }],
310
+ },
311
+ };
312
+ }
313
+ exports.default = configFactory;
@@ -0,0 +1,13 @@
1
+ import webpack from 'webpack';
2
+ import { type OptionsT as BaseOptionsT } from './app-base';
3
+ type OptionsT = BaseOptionsT & {
4
+ dontUseHmr?: boolean;
5
+ dontUseReactGlobalStateDebugging?: boolean;
6
+ };
7
+ /**
8
+ * @param ops
9
+ * @param [ops.dontUseReactGlobalStateDebugging]
10
+ * @param [ops.dontUseHmr]
11
+ */
12
+ export default function configFactory(ops: OptionsT): webpack.Configuration;
13
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /**
7
+ * @category Configs
8
+ * @module webpack/app-development
9
+ * @desc development Webpack configuration for applications.
10
+ */
11
+ const lodash_1 = require("lodash");
12
+ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
13
+ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
14
+ const webpack_1 = __importDefault(require("webpack"));
15
+ const webpack_merge_1 = require("webpack-merge");
16
+ const app_base_1 = __importDefault(require("./app-base"));
17
+ /**
18
+ * @param ops
19
+ * @param [ops.dontUseReactGlobalStateDebugging]
20
+ * @param [ops.dontUseHmr]
21
+ */
22
+ function configFactory(ops) {
23
+ const o = (0, lodash_1.defaults)((0, lodash_1.clone)(ops), {
24
+ cssLocalIdent: '[package]___[path][name]___[local]___[hash:base64:6]',
25
+ });
26
+ const entry = ['@dr.pogodin/react-utils/build/development/client/init'];
27
+ if (!o.dontUseHmr)
28
+ entry.push('webpack-hot-middleware/client?reload=true');
29
+ entry.push(...Array.isArray(o.entry) ? o.entry : [o.entry]);
30
+ const plugins = [
31
+ new mini_css_extract_plugin_1.default({
32
+ chunkFilename: '[id].css',
33
+ filename: '[id].css',
34
+ }),
35
+ new webpack_1.default.DefinePlugin({
36
+ 'process.env.BABEL_ENV': JSON.stringify('development'),
37
+ 'process.env.DEV_TOOLS': JSON.stringify(true),
38
+ 'process.env.NODE_ENV': JSON.stringify('development'),
39
+ 'process.env.REACT_GLOBAL_STATE_DEBUG': JSON.stringify(!o.dontUseReactGlobalStateDebugging),
40
+ }),
41
+ ];
42
+ // TODO: There should be no reason to include these plugins when HMR is opted
43
+ // out, however if I remove them, the compilation fails with obscure
44
+ // "ReferenceError: $RefreshReg$ is not defined" error. For now it seems
45
+ // fine to keep these plugins anyway, thus the shortcut of "if" condition
46
+ // below.
47
+ if (true || !o.dontUseHmr) {
48
+ plugins.push(new webpack_1.default.HotModuleReplacementPlugin(), new react_refresh_webpack_plugin_1.default({
49
+ overlay: {
50
+ sockIntegration: 'whm',
51
+ },
52
+ }));
53
+ }
54
+ const res = (0, webpack_merge_1.merge)((0, app_base_1.default)(Object.assign(Object.assign({}, o), { babelEnv: 'development', entry, mode: 'development' })), {
55
+ output: {
56
+ chunkFilename: '[id].js',
57
+ filename: '[id].js',
58
+ },
59
+ plugins,
60
+ snapshot: {
61
+ // This enforces Webpack to watch for possible changes in node_modules
62
+ // dependencies, which is a great convenience in library-centric dev
63
+ // workflows.
64
+ managedPaths: [],
65
+ },
66
+ });
67
+ return res;
68
+ }
69
+ exports.default = configFactory;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @category Configs
3
+ * @module webpack/app-production
4
+ * @desc Production Webpack configuration for applications.
5
+ */
6
+ import { type Configuration } from 'webpack';
7
+ import { type OptionsT as BaseOptionsT } from './app-base';
8
+ type OptionsT = BaseOptionsT;
9
+ /**
10
+ * @param {object} ops
11
+ * @param {string} ops.context Base URL for resolution of relative config paths.
12
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
13
+ * be created at the disk during the compilation.
14
+ */
15
+ export default function configFactory(ops: OptionsT): Configuration;
16
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * @category Configs
4
+ * @module webpack/app-production
5
+ * @desc Production Webpack configuration for applications.
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
12
+ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
13
+ const webpack_1 = __importDefault(require("webpack"));
14
+ const webpack_merge_1 = require("webpack-merge");
15
+ const app_base_1 = __importDefault(require("./app-base"));
16
+ /**
17
+ * @param {object} ops
18
+ * @param {string} ops.context Base URL for resolution of relative config paths.
19
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
20
+ * be created at the disk during the compilation.
21
+ */
22
+ function configFactory(ops) {
23
+ const entry = [
24
+ '@dr.pogodin/react-utils/build/production/client/init',
25
+ ...Array.isArray(ops.entry) ? ops.entry : [ops.entry],
26
+ ];
27
+ const res = (0, webpack_merge_1.merge)((0, app_base_1.default)(Object.assign(Object.assign({}, ops), { babelEnv: 'production', entry, mode: 'production' })), {
28
+ optimization: {
29
+ minimizer: [
30
+ '...',
31
+ new css_minimizer_webpack_plugin_1.default({
32
+ minimizerOptions: {
33
+ preset: ['default', {
34
+ /* Due to the way our styles are organized, these dangerous
35
+ * optimizations can break our styles, thus they are disabled. */
36
+ discardUnused: false,
37
+ reduceIdents: false,
38
+ zindex: false,
39
+ }],
40
+ },
41
+ }),
42
+ ],
43
+ },
44
+ plugins: [
45
+ new webpack_1.default.DefinePlugin({
46
+ 'process.env.BABEL_ENV': JSON.stringify('production'),
47
+ 'process.env.NODE_ENV': JSON.stringify('production'),
48
+ }),
49
+ new mini_css_extract_plugin_1.default({
50
+ chunkFilename: '[contenthash].css',
51
+ filename: '[contenthash].css',
52
+ }),
53
+ ],
54
+ });
55
+ return res;
56
+ }
57
+ exports.default = configFactory;
@@ -0,0 +1,20 @@
1
+ import { type Configuration } from 'webpack';
2
+ export type OptionsT = {
3
+ babelEnv: string;
4
+ babelLoaderOptions?: object;
5
+ context: string;
6
+ cssLocalIdent?: string;
7
+ dontUseProgressPlugin?: boolean;
8
+ entry: string | string[];
9
+ library: string;
10
+ mode: 'development' | 'none' | 'production';
11
+ outputPath?: string;
12
+ typescript?: boolean;
13
+ };
14
+ /**
15
+ * @param {object} ops
16
+ * @param {boolean} [ops.dontUseProgressPlugin] Set to not include progress
17
+ * plugin.
18
+ * @return {object}
19
+ */
20
+ export default function configFactory(ops: OptionsT): Configuration;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ // Base Webpack config for ReactJS libraries.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const autoprefixer_1 = __importDefault(require("autoprefixer"));
9
+ const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
10
+ const webpack_1 = require("webpack");
11
+ const utils_1 = require("@dr.pogodin/babel-plugin-react-css-modules/utils");
12
+ /**
13
+ * @param {object} ops
14
+ * @param {boolean} [ops.dontUseProgressPlugin] Set to not include progress
15
+ * plugin.
16
+ * @return {object}
17
+ */
18
+ function configFactory(ops) {
19
+ const plugins = [
20
+ new mini_css_extract_plugin_1.default({ filename: 'style.css' }),
21
+ ];
22
+ if (!ops.dontUseProgressPlugin)
23
+ plugins.push(new webpack_1.ProgressPlugin());
24
+ return {
25
+ context: ops.context,
26
+ entry: ops.entry,
27
+ externals: [
28
+ /@babel\/runtime/,
29
+ '@dr.pogodin/react-global-state',
30
+ '@dr.pogodin/js-utils',
31
+ '@dr.pogodin/react-themes',
32
+ '@dr.pogodin/react-utils',
33
+ 'axios',
34
+ 'dayjs',
35
+ 'lodash',
36
+ /node-forge/,
37
+ 'prop-types',
38
+ 'qs',
39
+ 'react',
40
+ /react-dom/,
41
+ 'react-helmet',
42
+ 'react-router-dom',
43
+ 'uuid',
44
+ ],
45
+ mode: ops.mode,
46
+ output: {
47
+ filename: 'web.bundle.js',
48
+ // TODO: Check, whether this fix can be dropped.
49
+ // Workaround to fix umd build, restore webpack v3 behaviour
50
+ // https://github.com/webpack/webpack/issues/6677
51
+ // https://github.com/webpack/webpack/issues/6642
52
+ globalObject: "typeof self !== 'undefined' ? self : this",
53
+ library: ops.library,
54
+ path: ops.outputPath,
55
+ libraryTarget: 'umd',
56
+ },
57
+ plugins,
58
+ module: {
59
+ rules: [{
60
+ /* Handles font imports in url(..) instructions in CSS. Effectively,
61
+ * with such configuration it just rewrites those URLs to point to
62
+ * the original location of the font assets in
63
+ * the library being build. */
64
+ test: /\.(eot|otf|svg|ttf|woff2?)$/,
65
+ include: [
66
+ /node_modules/,
67
+ /src[/\\]assets[/\\]fonts/,
68
+ ],
69
+ type: 'asset/resource',
70
+ generator: {
71
+ // TODO: This comes from the older config version which relied on
72
+ // file-loader. It might require some correction to correctly join
73
+ // `publicPath` and `filename`.
74
+ filename: '../shared/[path][name][ext]',
75
+ publicPath: `${ops.library}/build/shared`,
76
+ },
77
+ }, {
78
+ /* Loads JS and JSX moudles, and inlines SVG assets. */
79
+ test: ops.typescript ? /\.((j|t)sx?|svg)$/ : /\.(jsx?|svg)$/,
80
+ exclude: [
81
+ /node_modules/,
82
+ /src[/\\]assets[/\\]fonts/,
83
+ ],
84
+ loader: 'babel-loader',
85
+ options: Object.assign({ babelrc: false, configFile: false, envName: ops.babelEnv, presets: [
86
+ // NOTE: For the compilation of this very library (react-utils),
87
+ // this plugin path is overriden in webpack.config.js in the root of
88
+ // the codebase.
89
+ ['@dr.pogodin/react-utils/config/babel/webpack', {
90
+ noRR: true,
91
+ typescript: ops.typescript,
92
+ }],
93
+ ] }, ops.babelLoaderOptions || {}),
94
+ }, {
95
+ /* Loads SCSS stylesheets. */
96
+ test: /\.scss/,
97
+ exclude: /node_modules/,
98
+ use: [
99
+ mini_css_extract_plugin_1.default.loader, {
100
+ loader: 'css-loader',
101
+ options: {
102
+ importLoaders: 3,
103
+ modules: {
104
+ getLocalIdent: utils_1.getLocalIdent,
105
+ localIdentName: ops.cssLocalIdent,
106
+ },
107
+ },
108
+ }, {
109
+ loader: 'postcss-loader',
110
+ options: {
111
+ postcssOptions: {
112
+ plugins: [
113
+ autoprefixer_1.default,
114
+ ],
115
+ },
116
+ },
117
+ }, 'resolve-url-loader', {
118
+ loader: 'sass-loader',
119
+ options: {
120
+ sourceMap: true,
121
+ },
122
+ },
123
+ ],
124
+ }, {
125
+ /* Loads CSS stylesheets. It is assumed that CSS stylesheets come only
126
+ * from dependencies, as we use SCSS inside our own code. */
127
+ test: /\.css$/,
128
+ use: [
129
+ mini_css_extract_plugin_1.default.loader,
130
+ 'css-loader',
131
+ ],
132
+ }],
133
+ },
134
+ resolve: {
135
+ alias: {
136
+ /* Aliases to JS an JSX files are handled by Babel. */
137
+ assets: path_1.default.resolve(ops.context, 'src/assets'),
138
+ components: path_1.default.resolve(ops.context, 'src/shared/components'),
139
+ fonts: path_1.default.resolve(ops.context, 'src/assets/fonts'),
140
+ styles: path_1.default.resolve(ops.context, 'src/styles'),
141
+ },
142
+ extensions: [
143
+ '.ts',
144
+ '.tsx',
145
+ '.js',
146
+ '.jsx',
147
+ '.json',
148
+ '.scss',
149
+ ],
150
+ symlinks: false,
151
+ },
152
+ };
153
+ }
154
+ exports.default = configFactory;
@@ -0,0 +1,5 @@
1
+ import webpack from 'webpack';
2
+ import { type OptionsT as BaseOptionsT } from './lib-base';
3
+ type OptionsT = BaseOptionsT;
4
+ export default function configFactory(ops: OptionsT): webpack.Configuration;
5
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // Development Webpack config for ReactJS libraries.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const webpack_1 = __importDefault(require("webpack"));
9
+ const webpack_merge_1 = require("webpack-merge");
10
+ const lib_base_1 = __importDefault(require("./lib-base"));
11
+ function configFactory(ops) {
12
+ return (0, webpack_merge_1.merge)((0, lib_base_1.default)(Object.assign(Object.assign({}, ops), { babelEnv: 'development', cssLocalIdent: '[package]___[path][name]___[local]___[hash:base64:6]', mode: 'development', outputPath: path_1.default.resolve(__dirname, ops.context, 'build/development') })), {
13
+ plugins: [
14
+ new webpack_1.default.DefinePlugin({
15
+ // Dev. build of the library wraps modules inside eval() statements,
16
+ // hiding BUILD_INFO literals from the host code's Webpack build, thus
17
+ // leaving them undefined. As a work around, let's get it via global
18
+ // window object.
19
+ BUILD_INFO: 'window.__DEV_BUILD_INFO__',
20
+ 'process.env.BABEL_ENV': JSON.stringify('development'),
21
+ 'process.env.NODE_ENV': JSON.stringify('development'),
22
+ 'process.env.REACT_GLOBAL_STATE_DEBUG': JSON.stringify(true),
23
+ }),
24
+ ],
25
+ snapshot: {
26
+ // This enforces Webpack to watch for possible changes in node_modules
27
+ // dependencies, which is a great convenience in library-centric dev
28
+ // workflows.
29
+ managedPaths: [],
30
+ },
31
+ });
32
+ }
33
+ exports.default = configFactory;
@@ -0,0 +1,5 @@
1
+ import webpack from 'webpack';
2
+ import { type OptionsT as BaseOptionsT } from './lib-base';
3
+ type OptionsT = BaseOptionsT;
4
+ export default function configFactory(ops: OptionsT): webpack.Configuration;
5
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // Production Webpack config for ReactJS libraries.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const css_minimizer_webpack_plugin_1 = __importDefault(require("css-minimizer-webpack-plugin"));
9
+ const webpack_1 = __importDefault(require("webpack"));
10
+ const webpack_merge_1 = require("webpack-merge");
11
+ const lib_base_1 = __importDefault(require("./lib-base"));
12
+ function configFactory(ops) {
13
+ const baseConfig = (0, lib_base_1.default)(Object.assign(Object.assign({}, ops), { babelEnv: 'production', cssLocalIdent: '[hash:base64:6]', mode: 'production', outputPath: path_1.default.resolve(__dirname, ops.context, 'build/production') }));
14
+ return (0, webpack_merge_1.merge)(baseConfig, {
15
+ devtool: 'source-map',
16
+ optimization: {
17
+ minimizer: [
18
+ '...',
19
+ new css_minimizer_webpack_plugin_1.default({
20
+ minimizerOptions: {
21
+ preset: ['default', {
22
+ /* Due to the way our styles are organized, these dangerous
23
+ * optimizations can break our styles, thus they are disabled. */
24
+ discardUnused: false,
25
+ reduceIdents: false,
26
+ zindex: false,
27
+ }],
28
+ },
29
+ }),
30
+ ],
31
+ },
32
+ plugins: [
33
+ new webpack_1.default.DefinePlugin({
34
+ 'process.env.BABEL_ENV': JSON.stringify('production'),
35
+ 'process.env.NODE_ENV': JSON.stringify('production'),
36
+ }),
37
+ ],
38
+ });
39
+ }
40
+ exports.default = configFactory;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.0",
2
+ "version": "1.26.1",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"