@raisenow/tamaro-cli 1.9.0-dev.3 → 3.0.0-dev.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.
@@ -1,347 +0,0 @@
1
- import { H as logTitle, M as HTTPS_KEY_FILE, R as logDataTable, a as getIfCoreFns, i as extensions, j as HTTPS_CRT_FILE, o as getPaths, p as resolveEslintPluginConfig, r as getEnvVars, s as getRelativePaths, u as resolveApp } from "./env-DZ3cWM6p.js";
2
- import { createRequire } from "node:module";
3
- import { existsSync } from "node:fs";
4
- import path from "node:path";
5
- import { getIfUtils, removeEmpty } from "webpack-config-utils";
6
- import { globSync } from "glob";
7
- import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
8
- import StatoscopeWebpackPlugin from "@statoscope/webpack-plugin";
9
- import { CleanWebpackPlugin } from "clean-webpack-plugin";
10
- import CopyPlugin from "copy-webpack-plugin";
11
- import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
12
- import ESLintPlugin from "eslint-webpack-plugin";
13
- import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
14
- import HtmlWebpackPlugin from "html-webpack-plugin";
15
- import MiniCssExtractPlugin from "mini-css-extract-plugin";
16
- import TerserPlugin from "terser-webpack-plugin";
17
- import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
18
- import webpack from "webpack";
19
- import "webpack-dev-server";
20
- import escapeStringRegexp from "escape-string-regexp";
21
- //#region src/lib/InterpolateHtmlPlugin.ts
22
- const PLUGIN_NAME = "InterpolateHtmlPlugin";
23
- var InterpolateHtmlPlugin = class {
24
- replacements;
25
- constructor(replacements) {
26
- this.replacements = { ...replacements };
27
- }
28
- apply(compiler) {
29
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
30
- const hooks = HtmlWebpackPlugin.getHooks(compilation);
31
- hooks.alterAssetTagGroups.tap(PLUGIN_NAME, (assets) => {
32
- const publicUrl = this.replacements.PUBLIC_URL ?? "";
33
- const entry = assets.headTags[0].attributes.src;
34
- this.replacements.ENTRY = `${publicUrl}${entry}`;
35
- return assets;
36
- });
37
- hooks.afterTemplateExecution.tap(PLUGIN_NAME, (data) => {
38
- Object.entries(this.replacements).forEach(([key, value]) => {
39
- data.html = data.html.replaceAll(new RegExp(`%${escapeStringRegexp(key)}%`, "g"), value ?? "");
40
- });
41
- return data;
42
- });
43
- });
44
- }
45
- };
46
- //#endregion
47
- //#region src/webpack.config.ts
48
- const require = createRequire(import.meta.url);
49
- const imageInlineSizeLimit = 0;
50
- const getWebpackConfig = (env) => {
51
- const { ifMin, ifNotMin } = getIfUtils(env, ["min"]);
52
- const { ifAnalyze } = getIfUtils(env, ["analyze"]);
53
- const { ifHttps } = getIfUtils(env, ["https"]);
54
- const { ifLocalCore } = getIfUtils(env, ["localCore"]);
55
- const { ifDebug } = getIfUtils(env, ["debug"]);
56
- const { ifCore } = getIfCoreFns();
57
- const paths = getPaths(ifCore);
58
- const appHtmlFiles = globSync(paths.appHtml);
59
- const envVars = getEnvVars(globSync(paths.appEnv), ifMin, ifCore, ifLocalCore, ifHttps);
60
- const { ifHmr } = getIfUtils({ hmr: process.env.HMR_ENABLED === "true" }, ["hmr"]);
61
- const { ifNolint } = getIfUtils(env, ["nolint"]);
62
- const useTailwind = ifCore() && paths.appTailwindConfig && existsSync(paths.appTailwindConfig);
63
- const eslintPluginConfig = resolveEslintPluginConfig(paths);
64
- logTitle("Paths:");
65
- logDataTable(getRelativePaths(paths));
66
- logTitle("Environment variables:");
67
- logDataTable(envVars.raw);
68
- const getCssLoaders = ({ styleLoader = true, sassLoader = true, ...cssOptions }) => {
69
- const importLoaders = sassLoader ? 3 : 1;
70
- return removeEmpty([
71
- styleLoader ? ifMin({ loader: MiniCssExtractPlugin.loader }) : void 0,
72
- styleLoader ? ifNotMin({
73
- loader: require.resolve("style-loader"),
74
- options: { attributes: { "data-widget": process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET } }
75
- }) : void 0,
76
- {
77
- loader: require.resolve("css-loader"),
78
- options: {
79
- sourceMap: ifNotMin(),
80
- importLoaders,
81
- ...cssOptions
82
- }
83
- },
84
- {
85
- loader: require.resolve("postcss-loader"),
86
- options: { postcssOptions: { plugins: removeEmpty([
87
- !sassLoader ? require.resolve("postcss-import") : void 0,
88
- !sassLoader ? require.resolve("postcss-nested") : void 0,
89
- useTailwind ? [require.resolve("tailwindcss", { paths: [paths.appNodeModules] }), paths.appTailwindConfig] : void 0,
90
- require.resolve("autoprefixer")
91
- ]) } }
92
- },
93
- sassLoader ? {
94
- loader: require.resolve("resolve-url-loader"),
95
- options: { sourceMap: ifNotMin() }
96
- } : void 0,
97
- sassLoader ? {
98
- loader: require.resolve("sass-loader"),
99
- options: {
100
- api: "modern-compiler",
101
- sourceMap: true
102
- }
103
- } : void 0
104
- ]);
105
- };
106
- return removeEmpty({
107
- mode: ifMin("production", "development"),
108
- resolve: {
109
- symlinks: true,
110
- extensions: [...extensions, "..."],
111
- modules: [paths.appNodeModules, "node_modules"],
112
- alias: { "core-js": path.dirname(require.resolve("core-js/package.json")) },
113
- plugins: [new TsconfigPathsPlugin({
114
- configFile: paths.appTsConfig,
115
- extensions
116
- })]
117
- },
118
- entry: paths.appEntry,
119
- output: {
120
- publicPath: "auto",
121
- path: ifMin(paths.appDist, void 0),
122
- pathinfo: false,
123
- filename: ifCore("index.js", "widget.js"),
124
- chunkFilename: ifMin("[name]-[contenthash:16].js", "[name].js"),
125
- assetModuleFilename: "assets/[name]-[contenthash:16][ext]",
126
- crossOriginLoading: "anonymous",
127
- uniqueName: process.env.WEBPACK_UNIQUE_NAME
128
- },
129
- stats: ifAnalyze({ all: void 0 }, {
130
- modules: false,
131
- children: false,
132
- chunks: false,
133
- env: true,
134
- entrypoints: true,
135
- errorDetails: true
136
- }),
137
- module: { rules: removeEmpty([{
138
- test: /\.m?js$/,
139
- resolve: { fullySpecified: false }
140
- }, { oneOf: [
141
- (
142
- /**
143
- * App Javascript and Typescript (Babel)
144
- * and some dependencies distributed in a non-es5 formats
145
- */
146
- {
147
- test: /\.(js|ts|mjs)x?$/,
148
- include: ifCore([resolveApp("src"), resolveApp("node_modules")], [
149
- resolveApp("."),
150
- resolveApp("../../src"),
151
- resolveApp("../../node_modules")
152
- ]),
153
- exclude: [/node_modules[\\/]core-js/],
154
- loader: require.resolve("babel-loader"),
155
- options: {
156
- babelrc: false,
157
- configFile: false,
158
- sourceType: "unambiguous",
159
- sourceMaps: ifNotMin(),
160
- inputSourceMap: ifNotMin(),
161
- presets: [
162
- [require.resolve("@babel/preset-env"), {
163
- corejs: "3.49.0",
164
- debug: ifDebug(),
165
- modules: false,
166
- useBuiltIns: "usage",
167
- /**
168
- * Exclude plugins that interfere with MobX flow inference via makeAutoObservable.
169
- *
170
- * MobX detects generator methods on the prototype and wraps them as `flow` automatically.
171
- * Several Babel transforms break this detection:
172
- *
173
- * - transform-parameters: rewrites generator methods with default params (e.g. `*update(data, skip = false)`)
174
- * into plain functions returning an IIFE generator. makeAutoObservable then sees a regular function
175
- * and wraps it as `action` instead of `flow`.
176
- *
177
- * - async-to-generator / regenerator / async-generator-functions: downcompile async/generator syntax
178
- * to state-machine helpers, again making the methods invisible to MobX flow inference.
179
- *
180
- * All of these transforms are unnecessary — our browser targets support default parameters,
181
- * generators, and async functions natively.
182
- */
183
- exclude: [
184
- "@babel/plugin-transform-async-to-generator",
185
- "@babel/plugin-transform-regenerator",
186
- "@babel/plugin-proposal-async-generator-functions",
187
- "@babel/plugin-transform-parameters"
188
- ]
189
- }],
190
- [require.resolve("@babel/preset-typescript"), { allowDeclareFields: true }],
191
- [require.resolve("@babel/preset-react"), { runtime: "automatic" }]
192
- ],
193
- plugins: removeEmpty([
194
- require.resolve("@babel/plugin-syntax-dynamic-import"),
195
- require.resolve("babel-plugin-lodash"),
196
- ifHmr(require.resolve("react-refresh/babel")),
197
- ifNotMin(require.resolve("babel-plugin-istanbul"))
198
- ])
199
- }
200
- }),
201
- {
202
- test: /\.scss$/,
203
- resourceQuery: { not: [/inline/] },
204
- use: getCssLoaders({
205
- styleLoader: true,
206
- sassLoader: true
207
- })
208
- },
209
- {
210
- test: /\.css$/,
211
- resourceQuery: { not: [/inline/] },
212
- use: getCssLoaders({
213
- styleLoader: true,
214
- sassLoader: false
215
- })
216
- },
217
- {
218
- test: /\.scss$/,
219
- resourceQuery: /inline/,
220
- use: getCssLoaders({
221
- styleLoader: false,
222
- sassLoader: true,
223
- exportType: "string",
224
- sourceMap: false
225
- })
226
- },
227
- {
228
- test: /\.css$/,
229
- resourceQuery: /inline/,
230
- use: getCssLoaders({
231
- styleLoader: false,
232
- sassLoader: false,
233
- exportType: "string",
234
- sourceMap: false
235
- })
236
- },
237
- {
238
- test: /\.(png|jpe?g|svg|webp|gif|ico|ttf|eot|woff2?)$/,
239
- type: "asset",
240
- parser: { dataUrlCondition: { maxSize: imageInlineSizeLimit } }
241
- },
242
- {
243
- test: /\.ya?ml$/,
244
- use: [{ loader: require.resolve("json-loader") }, {
245
- loader: require.resolve("yaml-loader"),
246
- options: { asJSON: true }
247
- }]
248
- },
249
- {
250
- test: /\.html$/,
251
- loader: require.resolve("html-loader"),
252
- options: { minimize: false }
253
- },
254
- (
255
- /**
256
- * All other files - fallback
257
- * This must be the latest rule!
258
- */
259
- {
260
- exclude: [
261
- /^$/,
262
- /\.(js|jsx|ts|tsx|mjs)$/,
263
- /\.html$/,
264
- /\.json$/
265
- ],
266
- type: "asset/resource"
267
- })
268
- ] }]) },
269
- devtool: ifMin(false, "cheap-module-source-map"),
270
- devServer: {
271
- static: false,
272
- historyApiFallback: { disableDotRule: true },
273
- hot: ifHmr(),
274
- headers: { "Access-Control-Allow-Origin": "*" },
275
- allowedHosts: "all",
276
- client: { overlay: {
277
- warnings: false,
278
- errors: true
279
- } },
280
- server: ifHttps({
281
- type: "https",
282
- options: {
283
- cert: path.resolve(paths.root, HTTPS_CRT_FILE),
284
- key: path.resolve(paths.root, HTTPS_KEY_FILE)
285
- }
286
- })
287
- },
288
- optimization: {
289
- removeEmptyChunks: true,
290
- minimizer: [new TerserPlugin({ terserOptions: {
291
- keep_classnames: true,
292
- keep_fnames: true,
293
- compress: { passes: 2 }
294
- } }), new CssMinimizerPlugin()]
295
- },
296
- plugins: removeEmpty([
297
- new webpack.ProgressPlugin(),
298
- ifNolint() || !eslintPluginConfig ? void 0 : new ESLintPlugin(eslintPluginConfig),
299
- ifMin(new CleanWebpackPlugin({})),
300
- ...appHtmlFiles.map((file) => new HtmlWebpackPlugin({
301
- template: file,
302
- filename: path.basename(file),
303
- inject: false,
304
- minify: false
305
- })),
306
- new InterpolateHtmlPlugin(envVars.raw),
307
- new webpack.DefinePlugin(envVars.stringified),
308
- new ForkTsCheckerWebpackPlugin({ typescript: {
309
- typescriptPath: require.resolve("typescript", { paths: [paths.appNodeModules] }),
310
- configFile: paths.appTsConfig,
311
- mode: "write-references",
312
- diagnosticOptions: {
313
- syntactic: true,
314
- semantic: true,
315
- declaration: false,
316
- global: false
317
- }
318
- } }),
319
- ifHmr(new ReactRefreshWebpackPlugin()),
320
- ifMin(new MiniCssExtractPlugin({
321
- filename: "[name]-[contenthash:16].css",
322
- chunkFilename: "[name]-[contenthash:16].css",
323
- ignoreOrder: true,
324
- attributes: { "data-widget": process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET }
325
- })),
326
- new webpack.IgnorePlugin({
327
- resourceRegExp: /^\.\/locale$/,
328
- contextRegExp: /moment$/
329
- }),
330
- ifMin(new webpack.ids.HashedModuleIdsPlugin()),
331
- ifMin() && ifCore() ? new CopyPlugin({ patterns: ["*.md", "*.html"] }) : void 0,
332
- ifMin() && ifAnalyze() ? new StatoscopeWebpackPlugin({
333
- name: ifCore("tamaro-core", "tamaro-customer-config"),
334
- saveReportTo: "reports/report.html",
335
- saveStatsTo: "reports/stats-[name]-[hash].json",
336
- additionalStats: globSync("reports/*.json"),
337
- open: false
338
- }) : void 0
339
- ]),
340
- infrastructureLogging: {
341
- stream: process.stdout,
342
- appendOnly: false
343
- }
344
- });
345
- };
346
- //#endregion
347
- export { getWebpackConfig as default };