@dr.pogodin/react-utils 1.26.0 → 1.26.2
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/build/development/shared/components/ScalableRect/index.js +1 -1
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/web.bundle.js +1 -1
- package/build/production/shared/components/ScalableRect/index.js +1 -1
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.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/shared/components/Throbber/index.d.ts +1 -0
- package/config/babel/node-ssr.d.ts +17 -0
- package/config/babel/node-ssr.js +91 -0
- package/config/babel/webpack.d.ts +40 -0
- package/config/babel/webpack.js +107 -0
- package/config/webpack/app-base.d.ts +140 -0
- package/config/webpack/app-base.js +313 -0
- package/config/webpack/app-development.d.ts +13 -0
- package/config/webpack/app-development.js +69 -0
- package/config/webpack/app-production.d.ts +16 -0
- package/config/webpack/app-production.js +57 -0
- package/config/webpack/lib-base.d.ts +20 -0
- package/config/webpack/lib-base.js +154 -0
- package/config/webpack/lib-development.d.ts +5 -0
- package/config/webpack/lib-development.js +33 -0
- package/config/webpack/lib-production.d.ts +5 -0
- package/config/webpack/lib-production.js +40 -0
- package/package.json +3 -3
- package/src/shared/components/ScalableRect/index.tsx +1 -1
- package/src/shared/components/Throbber/index.tsx +1 -0
|
@@ -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`** — 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`** — UTC timestamp of the beginning of
|
|
115
|
+
* the build;
|
|
116
|
+
* - **`FRONT_END`** — 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`** — The value set for `BUILD_RNDKEY`;
|
|
127
|
+
* - **`timestamp`** — 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;
|