frosty 0.0.59 → 0.0.61

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.
Files changed (62) hide show
  1. package/README.md +80 -0
  2. package/dist/_native.d.ts +3 -3
  3. package/dist/_native.d.ts.map +1 -1
  4. package/dist/dom.d.ts +3 -3
  5. package/dist/dom.d.ts.map +1 -1
  6. package/dist/dom.js.map +1 -1
  7. package/dist/dom.mjs.map +1 -1
  8. package/dist/index.d.ts +7 -6
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/internals/common-3ehse_dX.js.map +1 -1
  13. package/dist/internals/{common-CfPzr225.d.ts → common-C7i6gn1g.d.ts} +3 -2
  14. package/dist/internals/common-C7i6gn1g.d.ts.map +1 -0
  15. package/dist/internals/{common-dr6cqGx7.d.ts → common-CIi50Iq9.d.ts} +3 -3
  16. package/dist/internals/common-CIi50Iq9.d.ts.map +1 -0
  17. package/dist/internals/common-uTufm_t7.mjs.map +1 -1
  18. package/dist/internals/component-BiP3XIPe.js.map +1 -1
  19. package/dist/internals/component-BzurKp_J.mjs.map +1 -1
  20. package/dist/internals/{fragment-Cf--4Zy4.d.ts → fragment-DE14AoyD.d.ts} +2 -2
  21. package/dist/internals/fragment-DE14AoyD.d.ts.map +1 -0
  22. package/dist/internals/renderer-BWXmkBT-.js.map +1 -1
  23. package/dist/internals/{renderer-CXpDNwSw.d.ts → renderer-DYV5MKJK.d.ts} +2 -2
  24. package/dist/internals/renderer-DYV5MKJK.d.ts.map +1 -0
  25. package/dist/internals/renderer-DgKjFDB-.mjs.map +1 -1
  26. package/dist/internals/runtime-DCKT7fd6.js.map +1 -1
  27. package/dist/internals/runtime-DK28Kyy2.mjs.map +1 -1
  28. package/dist/internals/state-N94hLsqm.js.map +1 -1
  29. package/dist/internals/state-j1YggBhW.mjs.map +1 -1
  30. package/dist/internals/sync-D_pTd9lu.mjs.map +1 -1
  31. package/dist/internals/sync-HGSokpPA.js.map +1 -1
  32. package/dist/internals/{utils-C0H65cOt.d.ts → utils-Cl4Iku8w.d.ts} +2 -2
  33. package/dist/internals/utils-Cl4Iku8w.d.ts.map +1 -0
  34. package/dist/jsx-runtime.d.ts +2 -2
  35. package/dist/jsx-runtime.d.ts.map +1 -1
  36. package/dist/jsx-runtime.js.map +1 -1
  37. package/dist/jsx-runtime.mjs.map +1 -1
  38. package/dist/server-dom.d.ts +3 -3
  39. package/dist/server-dom.d.ts.map +1 -1
  40. package/dist/server-dom.js.map +1 -1
  41. package/dist/server-dom.mjs.map +1 -1
  42. package/dist/web.d.ts +15 -8
  43. package/dist/web.d.ts.map +1 -1
  44. package/dist/web.js +137 -117
  45. package/dist/web.js.map +1 -1
  46. package/dist/web.mjs +138 -119
  47. package/dist/web.mjs.map +1 -1
  48. package/package.json +9 -16
  49. package/packages/frosty-cli/bin/frosty.sh +35 -0
  50. package/packages/frosty-cli/package.json +25 -0
  51. package/packages/frosty-cli/scripts/bin/run.sh +79 -0
  52. package/packages/frosty-cli/src/client/index.js +32 -0
  53. package/packages/frosty-cli/src/server/default.js +43 -0
  54. package/packages/frosty-cli/src/server/index.js +72 -0
  55. package/packages/frosty-cli/src/server/render.js +55 -0
  56. package/packages/frosty-cli/src/server/route.ts +81 -0
  57. package/packages/frosty-cli/webpack.js +282 -0
  58. package/dist/internals/common-CfPzr225.d.ts.map +0 -1
  59. package/dist/internals/common-dr6cqGx7.d.ts.map +0 -1
  60. package/dist/internals/fragment-Cf--4Zy4.d.ts.map +0 -1
  61. package/dist/internals/renderer-CXpDNwSw.d.ts.map +0 -1
  62. package/dist/internals/utils-C0H65cOt.d.ts.map +0 -1
@@ -0,0 +1,79 @@
1
+ #!/bin/sh
2
+ #
3
+ # run.sh
4
+ #
5
+ # The MIT License
6
+ # Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included in
16
+ # all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ # THE SOFTWARE.
25
+ #
26
+
27
+ set -e
28
+
29
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
30
+ cd "$SCRIPT_DIR"
31
+
32
+ export FROSTY_CLI_ROOT="$( realpath "$SCRIPT_DIR/../.." )"
33
+ export PROJECT_ROOT="${PROJECT_ROOT:-$( realpath "$INIT_CWD" )}"
34
+
35
+ cd "$PROJECT_ROOT"
36
+
37
+ POSITIONAL_ARGS=()
38
+
39
+ while [[ $# -gt 0 ]]; do
40
+ case $1 in
41
+ -w|--watch)
42
+ WATCH_MODE=true
43
+ shift
44
+ ;;
45
+ -d|--debug)
46
+ DEBUG_MODE=true
47
+ shift
48
+ ;;
49
+ -p|--port)
50
+ PORT="$2"
51
+ shift 2
52
+ ;;
53
+ -*)
54
+ echo "Unknown option $1"
55
+ print_usage
56
+ exit 1
57
+ ;;
58
+ *)
59
+ POSITIONAL_ARGS+=("$1") # save positional arg
60
+ shift # past argument
61
+ ;;
62
+ esac
63
+ done
64
+
65
+ set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
66
+
67
+ SCRIPT="npx webpack -c "$FROSTY_CLI_ROOT/webpack.js""
68
+
69
+ if [ $DEBUG_MODE ]; then
70
+ SCRIPT="$SCRIPT --mode development"
71
+ else
72
+ SCRIPT="$SCRIPT --mode production"
73
+ fi
74
+
75
+ if [ $WATCH ]; then
76
+ SCRIPT="$SCRIPT --watch"
77
+ fi
78
+
79
+ exec $SCRIPT
@@ -0,0 +1,32 @@
1
+ //
2
+ // index.js
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
25
+
26
+ import { DOMRenderer } from 'frosty/dom';
27
+ import * as __APPLICATION__ from '__APPLICATION__';
28
+
29
+ const { default: App } = __APPLICATION__;
30
+
31
+ const root = document.getElementById('root');
32
+ DOMRenderer.createRoot(root).mount(<App />);
@@ -0,0 +1,43 @@
1
+ //
2
+ // default.js
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
25
+
26
+ import { Server } from '@o2ter/server-js';
27
+
28
+ /** @type {Server.Options} */
29
+ export const serverOptions = {
30
+ http: 'v1',
31
+ express: {
32
+ cors: {
33
+ credentials: true,
34
+ origin: true,
35
+ },
36
+ rateLimit: {
37
+ windowMs: 1000,
38
+ limit: 1000,
39
+ },
40
+ },
41
+ };
42
+
43
+ export default () => {};
@@ -0,0 +1,72 @@
1
+ //
2
+ // index.js
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
25
+
26
+ import _ from 'lodash';
27
+ import path from 'path';
28
+ import { Server } from '@o2ter/server-js';
29
+ import { ReactRoute } from './route';
30
+ import * as __APPLICATIONS__ from '__APPLICATIONS__';
31
+
32
+ let __SERVER__ = {};
33
+ try {
34
+ __SERVER__ = await import('__SERVER__');
35
+ } catch(e) {
36
+ console.error(e);
37
+ };
38
+
39
+ const app = 'serverOptions' in __SERVER__ ? new Server(__SERVER__.serverOptions) : new Server;
40
+
41
+ app.use(Server.static(path.join(__dirname, 'public'), { cacheControl: true }));
42
+
43
+ const server_env = {};
44
+ if ('default' in __SERVER__) await __SERVER__.default(app, server_env);
45
+
46
+ for (const [name, { path, basename, env }] of _.toPairs(__applications__)) {
47
+ const { default: App } = __APPLICATIONS__[name];
48
+ const route = ReactRoute(App, {
49
+ env: {
50
+ ...server_env,
51
+ ...env,
52
+ },
53
+ jsSrc: `/${name}_bundle.js`,
54
+ cssSrc: `/css/${name}_bundle.css`,
55
+ basename: basename ?? '/',
56
+ preferredLocale: 'preferredLocale' in __SERVER__ ? (req) => __SERVER__.preferredLocale(app, name, req) : undefined,
57
+ resources: 'resources' in __SERVER__ ? (req) => __SERVER__.resources(app, name, req) : undefined,
58
+ });
59
+ if (_.isEmpty(path) || path === '/') {
60
+ app.use(route);
61
+ } else {
62
+ app.use(path, route);
63
+ }
64
+ }
65
+
66
+ app.use((err, req, res, next) => {
67
+ res.status(500).json(err instanceof Error ? { message: err.message } : err);
68
+ });
69
+
70
+ const PORT = !_.isEmpty(process.env.PORT) ? parseInt(process.env.PORT) : 8080;
71
+
72
+ app.listen(PORT, () => console.info(`listening on port ${PORT}`));
@@ -0,0 +1,55 @@
1
+ //
2
+ // render.ts
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
25
+
26
+ import _ from 'lodash';
27
+ import { ServerDOMRenderer } from 'frosty/server-dom';
28
+
29
+ export const renderToHTML = async (App, {
30
+ request,
31
+ response,
32
+ env,
33
+ jsSrc,
34
+ cssSrc,
35
+ basename,
36
+ preferredLocale,
37
+ resources: _resources,
38
+ }) => {
39
+
40
+ const component = (
41
+ <html>
42
+ <head>
43
+ <script src={jsSrc} defer />
44
+ <link rel='stylesheet' type='text/css' href={cssSrc} />
45
+ </head>
46
+ <body>
47
+ <div id="root"><App /></div>
48
+ </body>
49
+ </html>
50
+ );
51
+
52
+ const renderer = new ServerDOMRenderer();
53
+ response.setHeader('Content-Type', 'text/html');
54
+ response.send(await renderer.renderToString(component));
55
+ }
@@ -0,0 +1,81 @@
1
+ //
2
+ // route.ts
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
25
+
26
+ import _ from 'lodash';
27
+ import { Server, Request } from '@o2ter/server-js';
28
+ import cookieParser from 'cookie-parser';
29
+ import { renderToHTML } from './render';
30
+ import { Awaitable } from '@o2ter/utils-js';
31
+
32
+ type ReactRouteOptions = {
33
+ env: any;
34
+ jsSrc: string;
35
+ cssSrc: string;
36
+ basename: string;
37
+ preferredLocale?: (req: Request) => Awaitable<string | undefined>;
38
+ resources?: (req: Request) => Awaitable<any>;
39
+ }
40
+
41
+ const defaultPreferredLocale = (req: Request) => {
42
+ if (_.isString(req.cookies['PREFERRED_LOCALE'])) {
43
+ return req.cookies['PREFERRED_LOCALE'];
44
+ }
45
+ if (_.isString(req.headers['accept-language'])) {
46
+ const acceptLanguage = req.headers['accept-language'].split(',');
47
+ for (const language of acceptLanguage) {
48
+ return language.split(';')[0].trim();
49
+ }
50
+ }
51
+ }
52
+
53
+ export const ReactRoute = (App: any, {
54
+ env = {},
55
+ jsSrc,
56
+ cssSrc,
57
+ basename,
58
+ preferredLocale = defaultPreferredLocale,
59
+ resources,
60
+ }: ReactRouteOptions) => {
61
+
62
+ const router = Server.Router();
63
+ router.use(cookieParser() as any);
64
+
65
+ router.get('*', async (req, res) => {
66
+ const _preferredLocale = await preferredLocale(req);
67
+ res.cookie('PREFERRED_LOCALE', _preferredLocale, { maxAge: 31536000 });
68
+ await renderToHTML(App, {
69
+ request: req,
70
+ response: res,
71
+ env,
72
+ jsSrc,
73
+ cssSrc,
74
+ basename,
75
+ preferredLocale: _preferredLocale,
76
+ resources: await resources?.(req),
77
+ });
78
+ });
79
+
80
+ return router;
81
+ }
@@ -0,0 +1,282 @@
1
+ /* eslint no-var: 0 */
2
+
3
+ const _ = require('lodash');
4
+ const os = require('os');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const crypto = require('crypto');
8
+ const webpack = require('webpack');
9
+ const Dotenv = require('dotenv-webpack');
10
+ const TerserPlugin = require('terser-webpack-plugin');
11
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
12
+ const CopyPlugin = require('copy-webpack-plugin');
13
+
14
+ const serverConfig = (() => {
15
+ try {
16
+ return require(path.resolve(process.cwd(), 'server.config.js'));
17
+ } catch {
18
+ return {};
19
+ }
20
+ })();
21
+
22
+ const frosty = (() => {
23
+ try {
24
+ return require.resolve('frosty');
25
+ } catch {
26
+ return;
27
+ }
28
+ })();
29
+
30
+ const frostyDevPrj = (() => {
31
+ if (frosty) return {};
32
+ const { rollupConfig: { input } } = require(path.resolve(__dirname, '../../rollup.config.mjs'));
33
+ const resolved = {};
34
+ for (const [k, v] of _.entries(input)) {
35
+ if (k === 'index') continue;
36
+ resolved[`frosty/${k}`] = path.resolve(__dirname, '../..', v);
37
+ }
38
+ return {
39
+ ...resolved,
40
+ frosty: path.resolve(__dirname, '../../src/index'),
41
+ };
42
+ })();
43
+
44
+ module.exports = (env, argv) => {
45
+
46
+ const config = _.isFunction(serverConfig) ? serverConfig(env, argv) : serverConfig;
47
+ const IS_PRODUCTION = argv.mode !== 'development';
48
+
49
+ const babelLoaderConfiguration = ({ server }) => ({
50
+ test: /\.(ts|tsx|m?js)?$/i,
51
+ use: {
52
+ loader: 'babel-loader',
53
+ options: {
54
+ compact: IS_PRODUCTION,
55
+ cacheDirectory: true,
56
+ configFile: false,
57
+ presets: [
58
+ ['@babel/preset-env', {
59
+ exclude: [
60
+ '@babel/plugin-transform-regenerator',
61
+ '@babel/plugin-transform-async-generator-functions',
62
+ '@babel/plugin-transform-async-to-generator',
63
+ ],
64
+ targets: server ? { node: 'current' } : 'defaults',
65
+ ...server ? {} : config.polyfills ?? {},
66
+ }],
67
+ [
68
+ "@babel/preset-react",
69
+ {
70
+ development: !IS_PRODUCTION,
71
+ runtime: 'automatic',
72
+ importSource: 'frosty',
73
+ }
74
+ ],
75
+ '@babel/preset-typescript',
76
+ ]
77
+ },
78
+ },
79
+ resolve: {
80
+ fullySpecified: false,
81
+ },
82
+ });
83
+
84
+ const cssLoaderConfiguration = ({ server }) => ({
85
+ test: /\.(css|sass|scss)$/,
86
+ use: [
87
+ !server && MiniCssExtractPlugin.loader,
88
+ 'css-loader',
89
+ {
90
+ loader: 'postcss-loader',
91
+ options: {
92
+ postcssOptions: {
93
+ plugins: [
94
+ 'autoprefixer',
95
+ ],
96
+ }
97
+ }
98
+ },
99
+ 'sass-loader',
100
+ ].filter(Boolean),
101
+ });
102
+
103
+ const imageLoaderConfiguration = ({ server }) => ({
104
+ test: /\.(gif|jpe?g|a?png|svg)$/i,
105
+ use: {
106
+ loader: 'file-loader',
107
+ options: {
108
+ name: '[name].[contenthash].[ext]',
109
+ publicPath: '/images',
110
+ outputPath: '/images',
111
+ emitFile: !server,
112
+ }
113
+ }
114
+ });
115
+
116
+ const fontLoaderConfiguration = ({ server }) => ({
117
+ test: /\.ttf$/i,
118
+ use: {
119
+ loader: 'file-loader',
120
+ options: {
121
+ name: '[name].[contenthash].[ext]',
122
+ publicPath: '/fonts',
123
+ outputPath: '/fonts',
124
+ emitFile: !server,
125
+ }
126
+ }
127
+ });
128
+
129
+ const webpackOptimization = ({ server }) => ({
130
+ minimize: IS_PRODUCTION,
131
+ minimizer: [
132
+ new TerserPlugin({
133
+ parallel: true,
134
+ extractComments: false,
135
+ terserOptions: {
136
+ sourceMap: false,
137
+ compress: true,
138
+ keep_classnames: server,
139
+ format: {
140
+ comments: !IS_PRODUCTION,
141
+ },
142
+ },
143
+ }),
144
+ ],
145
+ });
146
+
147
+ const webpackConfiguration = {
148
+ mode: IS_PRODUCTION ? 'production' : 'development',
149
+ devtool: IS_PRODUCTION ? false : 'cheap-module-source-map',
150
+ experiments: {
151
+ topLevelAwait: true,
152
+ },
153
+ resolve: {
154
+ ...config.options?.resolve ?? {},
155
+ alias: {
156
+ ...frosty ? { frosty } : frostyDevPrj,
157
+ ...config.options?.resolve?.alias ?? {},
158
+ },
159
+ },
160
+ externals: config.options?.externals,
161
+ };
162
+
163
+ const webpackPlugins = [
164
+ new MiniCssExtractPlugin({ filename: 'css/[name].css' }),
165
+ new webpack.DefinePlugin({ __DEV__: JSON.stringify(!IS_PRODUCTION) }),
166
+ new Dotenv({ path: path.join(process.cwd(), '.env') }),
167
+ new Dotenv({ path: path.join(process.cwd(), '.env.local') }),
168
+ new webpack.ProvidePlugin({
169
+ _: 'lodash',
170
+ }),
171
+ ...config.options?.plugins ?? [],
172
+ ];
173
+
174
+ const server = config.serverEntry ? path.resolve(process.cwd(), config.serverEntry) : path.resolve(__dirname, './src/server/default.js');
175
+
176
+ const random = crypto.randomUUID();
177
+ const tempDir = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
178
+ const applications = path.resolve(tempDir, `applications-${random}.js`);
179
+
180
+ fs.writeFileSync(applications, `
181
+ ${_.map(config.client, ({ entry }, name) => `import * as ${name} from '${path.resolve(process.cwd(), entry)}';`).join('\n')}
182
+ export { ${_.keys(config.client).join(',')} };
183
+ `);
184
+
185
+ const moduleSuffixes = {
186
+ client: config.moduleSuffixes?.client ?? ['.browser', '.web', ''],
187
+ server: config.moduleSuffixes?.server ?? ['.node', '.server', '.web', ''],
188
+ };
189
+
190
+ return [
191
+ ..._.map(config.client, ({ entry }, name) => ({
192
+ ...webpackConfiguration,
193
+ optimization: webpackOptimization({ server: false }),
194
+ plugins: webpackPlugins,
195
+ entry: {
196
+ [`${name}_bundle`]: [
197
+ 'core-js/stable',
198
+ path.resolve(__dirname, './client/index.js'),
199
+ ],
200
+ },
201
+ output: {
202
+ path: config.output ? path.join(config.output, 'public') : path.join(__dirname, 'dist/public'),
203
+ },
204
+ resolve: {
205
+ ...webpackConfiguration.resolve,
206
+ alias: {
207
+ ...webpackConfiguration.resolve.alias,
208
+ __APPLICATION__: path.resolve(process.cwd(), entry),
209
+ },
210
+ extensions: [
211
+ ...moduleSuffixes.client.flatMap(x => [`${x}.tsx`, `${x}.jsx`]),
212
+ ...moduleSuffixes.client.flatMap(x => [`${x}.ts`, `${x}.mjs`, `${x}.js`]),
213
+ '...'
214
+ ],
215
+ },
216
+ module: {
217
+ rules: [
218
+ babelLoaderConfiguration({ server: false }),
219
+ cssLoaderConfiguration({ server: false }),
220
+ imageLoaderConfiguration({ server: false }),
221
+ fontLoaderConfiguration({ server: false }),
222
+ ...config.options?.module?.rules ?? [],
223
+ ]
224
+ }
225
+ })),
226
+ {
227
+ ...webpackConfiguration,
228
+ optimization: webpackOptimization({ server: false }),
229
+ plugins: _.compact([
230
+ ...webpackPlugins,
231
+ ...config.options?.server?.plugins ?? [],
232
+ config.serverAssets && new CopyPlugin({ patterns: config.serverAssets }),
233
+ ]),
234
+ target: 'node',
235
+ plugins: webpackPlugins,
236
+ entry: {
237
+ server: [
238
+ 'core-js/stable',
239
+ path.resolve(__dirname, './src/server/index.js'),
240
+ ],
241
+ },
242
+ output: {
243
+ path: config.output || path.resolve(__dirname, 'dist'),
244
+ },
245
+ resolve: {
246
+ ...webpackConfiguration.resolve,
247
+ alias: {
248
+ ...webpackConfiguration.resolve.alias,
249
+ __APPLICATIONS__: applications,
250
+ __SERVER__: server,
251
+ },
252
+ extensions: [
253
+ ...moduleSuffixes.server.flatMap(x => [`${x}.tsx`, `${x}.jsx`]),
254
+ ...moduleSuffixes.server.flatMap(x => [`${x}.ts`, `${x}.mjs`, `${x}.js`]),
255
+ '...'
256
+ ],
257
+ },
258
+ module: {
259
+ rules: [
260
+ babelLoaderConfiguration({ server: true }),
261
+ cssLoaderConfiguration({ server: true }),
262
+ imageLoaderConfiguration({ server: true }),
263
+ fontLoaderConfiguration({ server: true }),
264
+ {
265
+ test: /\.node$/,
266
+ use: {
267
+ loader: 'node-loader',
268
+ options: {
269
+ name: '[name].[contenthash].[ext]',
270
+ }
271
+ }
272
+ },
273
+ ...config.options?.module?.rules ?? [],
274
+ ...config.options?.server?.module?.rules ?? [],
275
+ ]
276
+ },
277
+ performance: {
278
+ hints: false,
279
+ }
280
+ }
281
+ ];
282
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"common-CfPzr225.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"common-dr6cqGx7.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fragment-Cf--4Zy4.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderer-CXpDNwSw.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-C0H65cOt.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}