@intlayer/webpack 9.0.0-canary.14 → 9.0.0-canary.15

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.
@@ -20,6 +20,14 @@ var IntlayerPlugin = class {
20
20
  const { webpack } = compiler;
21
21
  const isBuild = compiler.options.mode !== "development";
22
22
  const appLogger = (0, _intlayer_config_logger.getAppLogger)(this.configuration);
23
+ compiler.hooks.beforeCompile.tapPromise("IntlayerPlugin", async () => {
24
+ if (!this.isWatching) try {
25
+ await (0, _intlayer_engine_build.prepareIntlayer)(this.configuration);
26
+ this.isWatching = true;
27
+ } catch (error) {
28
+ appLogger(`Error in IntlayerPlugin: ${error}`, { level: "error" });
29
+ }
30
+ });
23
31
  const wrapKey = (key) => `process.env.${key}`;
24
32
  const wrapValue = (value) => `"${value}"`;
25
33
  let env = { ...(0, _intlayer_config_envVars.getConfigEnvVars)(this.configuration, wrapKey, wrapValue) };
@@ -38,15 +46,7 @@ var IntlayerPlugin = class {
38
46
  "process.env": "({})",
39
47
  ...env
40
48
  }).apply(compiler);
41
- if (this.configuration.content.watch) await (0, _intlayer_engine_watcher.watch)({ configuration: this.configuration });
42
- compiler.hooks.beforeCompile.tapPromise("IntlayerPlugin", async () => {
43
- if (!this.isWatching) try {
44
- await (0, _intlayer_engine_build.prepareIntlayer)(this.configuration);
45
- this.isWatching = true;
46
- } catch (error) {
47
- appLogger(`Error in IntlayerPlugin: ${error}`, { level: "error" });
48
- }
49
- });
49
+ if (!isBuild && this.configuration.content.watch) await (0, _intlayer_engine_watcher.watch)({ configuration: this.configuration });
50
50
  }
51
51
  };
52
52
 
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-plugin.cjs","names":["BLUE"],"sources":["../../src/webpack-plugin.ts"],"sourcesContent":["import { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Compiler } from 'webpack';\n\n// Watch mode or on time build\nexport class IntlayerPlugin {\n private isWatching = false; // Flag to ensure we only start the watcher after the first build\n private configuration;\n\n constructor(configuration?: IntlayerConfig) {\n this.configuration = configuration ?? getConfiguration();\n }\n\n async apply(compiler: Compiler): Promise<void> {\n const { webpack } = compiler;\n\n const isBuild = compiler.options.mode !== 'development';\n\n const appLogger = getAppLogger(this.configuration);\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n // Specific `process.env.<KEY>` defines. webpack's DefinePlugin replaces both\n // the dot- and bracket-notation reads of a defined key, and — crucially —\n // folds them at *parse* time, which lets it dead-code-eliminate the guarded\n // dynamic `import()` chunks (e.g. the HTML/markdown renderers) for unused\n // node types. The config flags are emitted in every mode so routing/editor\n // behaviour is correct in dev too; the dictionary scan (used to prune node\n // types) only runs for production builds.\n let env: Record<string, string> = {\n ...getConfigEnvVars(this.configuration, wrapKey, wrapValue),\n };\n\n if (isBuild) {\n const dictionaries = getDictionaries(this.configuration);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out plugins:',\n unusedNodeTypes.map((key) => colorize(key, BLUE)).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shaking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n ),\n };\n }\n\n new webpack.DefinePlugin({\n // Catch-all so that any `process.env.*` read NOT folded by the specific\n // keys below still resolves to `undefined` instead of dereferencing a\n // bare `process`, which is not defined in browser bundles (e.g. Angular)\n // and throws `process is not defined`. This covers in-use node types\n // (never emitted as \"false\"), the dictionary selector when present, and\n // every read in development where the dictionary scan is skipped. Specific\n // keys (below) and host bundler defines (e.g. `process.env.NODE_ENV`) take\n // precedence over this object, so chunk-level tree shaking is preserved.\n 'process.env': '({})',\n ...env,\n }).apply(compiler);\n\n if (this.configuration.content.watch) {\n // Start watching (assuming watch is also async)\n await watch({ configuration: this.configuration });\n }\n\n compiler.hooks.beforeCompile.tapPromise('IntlayerPlugin', async () => {\n if (!this.isWatching) {\n try {\n await prepareIntlayer(this.configuration);\n this.isWatching = true;\n } catch (error) {\n appLogger(`Error in IntlayerPlugin: ${error}`, {\n level: 'error',\n });\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,aAAa;CACrB,AAAQ;CAER,YAAY,eAAgC;AAC1C,OAAK,gBAAgB,8DAAmC;;CAG1D,MAAM,MAAM,UAAmC;EAC7C,MAAM,EAAE,YAAY;EAEpB,MAAM,UAAU,SAAS,QAAQ,SAAS;EAE1C,MAAM,sDAAyB,KAAK,cAAc;EAElD,MAAM,WAAW,QAAgB,eAAe;EAChD,MAAM,aAAa,UAAkB,IAAI,MAAM;EAS/C,IAAI,MAA8B,EAChC,kDAAoB,KAAK,eAAe,SAAS,UAAU,EAC5D;AAED,MAAI,SAAS;GACX,MAAM,iEAA+B,KAAK,cAAc;AAExD,OAAI,OAAO,KAAK,aAAa,CAAC,WAAW,EACvC,WAAU,2DAA2D,EACnE,WAAW,MACZ,CAAC;GAGJ,MAAM,kBAAkB,0DAA8B,aAAa;AAEnE,OAAI,mBAAmB,gBAAgB,SAAS,EAC9C,WACE,CACE,0BACA,gBAAgB,KAAK,8CAAiB,KAAKA,6BAAK,CAAC,CAAC,KAAK,KAAK,CAC7D,EACD,EACE,WAAW,MACZ,CACF;AAGH,SAAM;IACJ,GAAG;IAGH,wDAA0B,iBAAiB,SAAS,UAAU;IAI9D,qHAC2B,aAAa,EACtC,SACA,UACD;IACF;;AAGH,MAAI,QAAQ,aAAa;GASvB,eAAe;GACf,GAAG;GACJ,CAAC,CAAC,MAAM,SAAS;AAElB,MAAI,KAAK,cAAc,QAAQ,MAE7B,2CAAY,EAAE,eAAe,KAAK,eAAe,CAAC;AAGpD,WAAS,MAAM,cAAc,WAAW,kBAAkB,YAAY;AACpE,OAAI,CAAC,KAAK,WACR,KAAI;AACF,sDAAsB,KAAK,cAAc;AACzC,SAAK,aAAa;YACX,OAAO;AACd,cAAU,4BAA4B,SAAS,EAC7C,OAAO,SACR,CAAC;;IAGN"}
1
+ {"version":3,"file":"webpack-plugin.cjs","names":["BLUE"],"sources":["../../src/webpack-plugin.ts"],"sourcesContent":["import { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Compiler } from 'webpack';\n\n// Watch mode or on time build\nexport class IntlayerPlugin {\n private isWatching = false; // Flag to ensure we only start the watcher after the first build\n private configuration;\n\n constructor(configuration?: IntlayerConfig) {\n this.configuration = configuration ?? getConfiguration();\n }\n\n async apply(compiler: Compiler): Promise<void> {\n const { webpack } = compiler;\n\n const isBuild = compiler.options.mode !== 'development';\n\n const appLogger = getAppLogger(this.configuration);\n\n // Register the dictionary preparation tap *synchronously*, before any\n // `await` below. webpack does not await a plugin's async `apply`, so any\n // hook tapped after an `await` (e.g. after `watch()`) may register too late\n // — after `beforeCompile` has already fired — leaving the `.intlayer`\n // dictionaries entry unbuilt when module resolution starts and breaking the\n // build with `Can't resolve '@intlayer/dictionaries-entry'`. Tapping here\n // guarantees the entry is prepared before compilation begins.\n compiler.hooks.beforeCompile.tapPromise('IntlayerPlugin', async () => {\n if (!this.isWatching) {\n try {\n await prepareIntlayer(this.configuration);\n this.isWatching = true;\n } catch (error) {\n appLogger(`Error in IntlayerPlugin: ${error}`, {\n level: 'error',\n });\n }\n }\n });\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n // Specific `process.env.<KEY>` defines. webpack's DefinePlugin replaces both\n // the dot- and bracket-notation reads of a defined key, and — crucially —\n // folds them at *parse* time, which lets it dead-code-eliminate the guarded\n // dynamic `import()` chunks (e.g. the HTML/markdown renderers) for unused\n // node types. The config flags are emitted in every mode so routing/editor\n // behaviour is correct in dev too; the dictionary scan (used to prune node\n // types) only runs for production builds.\n let env: Record<string, string> = {\n ...getConfigEnvVars(this.configuration, wrapKey, wrapValue),\n };\n\n if (isBuild) {\n const dictionaries = getDictionaries(this.configuration);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out plugins:',\n unusedNodeTypes.map((key) => colorize(key, BLUE)).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shaking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n ),\n };\n }\n\n new webpack.DefinePlugin({\n // Catch-all so that any `process.env.*` read NOT folded by the specific\n // keys below still resolves to `undefined` instead of dereferencing a\n // bare `process`, which is not defined in browser bundles (e.g. Angular)\n // and throws `process is not defined`. This covers in-use node types\n // (never emitted as \"false\"), the dictionary selector when present, and\n // every read in development where the dictionary scan is skipped. Specific\n // keys (below) and host bundler defines (e.g. `process.env.NODE_ENV`) take\n // precedence over this object, so chunk-level tree shaking is preserved.\n 'process.env': '({})',\n ...env,\n }).apply(compiler);\n\n // Only watch content declarations for the dev server. A production build is\n // a one-off compilation: starting a file watcher there serves no purpose and\n // keeps a live `fsevents`/chokidar stream open for the whole build.\n if (!isBuild && this.configuration.content.watch) {\n // Start watching (assuming watch is also async)\n await watch({ configuration: this.configuration });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,aAAa;CACrB,AAAQ;CAER,YAAY,eAAgC;AAC1C,OAAK,gBAAgB,8DAAmC;;CAG1D,MAAM,MAAM,UAAmC;EAC7C,MAAM,EAAE,YAAY;EAEpB,MAAM,UAAU,SAAS,QAAQ,SAAS;EAE1C,MAAM,sDAAyB,KAAK,cAAc;AASlD,WAAS,MAAM,cAAc,WAAW,kBAAkB,YAAY;AACpE,OAAI,CAAC,KAAK,WACR,KAAI;AACF,sDAAsB,KAAK,cAAc;AACzC,SAAK,aAAa;YACX,OAAO;AACd,cAAU,4BAA4B,SAAS,EAC7C,OAAO,SACR,CAAC;;IAGN;EAEF,MAAM,WAAW,QAAgB,eAAe;EAChD,MAAM,aAAa,UAAkB,IAAI,MAAM;EAS/C,IAAI,MAA8B,EAChC,kDAAoB,KAAK,eAAe,SAAS,UAAU,EAC5D;AAED,MAAI,SAAS;GACX,MAAM,iEAA+B,KAAK,cAAc;AAExD,OAAI,OAAO,KAAK,aAAa,CAAC,WAAW,EACvC,WAAU,2DAA2D,EACnE,WAAW,MACZ,CAAC;GAGJ,MAAM,kBAAkB,0DAA8B,aAAa;AAEnE,OAAI,mBAAmB,gBAAgB,SAAS,EAC9C,WACE,CACE,0BACA,gBAAgB,KAAK,8CAAiB,KAAKA,6BAAK,CAAC,CAAC,KAAK,KAAK,CAC7D,EACD,EACE,WAAW,MACZ,CACF;AAGH,SAAM;IACJ,GAAG;IAGH,wDAA0B,iBAAiB,SAAS,UAAU;IAI9D,qHAC2B,aAAa,EACtC,SACA,UACD;IACF;;AAGH,MAAI,QAAQ,aAAa;GASvB,eAAe;GACf,GAAG;GACJ,CAAC,CAAC,MAAM,SAAS;AAKlB,MAAI,CAAC,WAAW,KAAK,cAAc,QAAQ,MAEzC,2CAAY,EAAE,eAAe,KAAK,eAAe,CAAC"}
@@ -18,6 +18,14 @@ var IntlayerPlugin = class {
18
18
  const { webpack } = compiler;
19
19
  const isBuild = compiler.options.mode !== "development";
20
20
  const appLogger = getAppLogger(this.configuration);
21
+ compiler.hooks.beforeCompile.tapPromise("IntlayerPlugin", async () => {
22
+ if (!this.isWatching) try {
23
+ await prepareIntlayer(this.configuration);
24
+ this.isWatching = true;
25
+ } catch (error) {
26
+ appLogger(`Error in IntlayerPlugin: ${error}`, { level: "error" });
27
+ }
28
+ });
21
29
  const wrapKey = (key) => `process.env.${key}`;
22
30
  const wrapValue = (value) => `"${value}"`;
23
31
  let env = { ...getConfigEnvVars(this.configuration, wrapKey, wrapValue) };
@@ -36,15 +44,7 @@ var IntlayerPlugin = class {
36
44
  "process.env": "({})",
37
45
  ...env
38
46
  }).apply(compiler);
39
- if (this.configuration.content.watch) await watch({ configuration: this.configuration });
40
- compiler.hooks.beforeCompile.tapPromise("IntlayerPlugin", async () => {
41
- if (!this.isWatching) try {
42
- await prepareIntlayer(this.configuration);
43
- this.isWatching = true;
44
- } catch (error) {
45
- appLogger(`Error in IntlayerPlugin: ${error}`, { level: "error" });
46
- }
47
- });
47
+ if (!isBuild && this.configuration.content.watch) await watch({ configuration: this.configuration });
48
48
  }
49
49
  };
50
50
 
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-plugin.mjs","names":[],"sources":["../../src/webpack-plugin.ts"],"sourcesContent":["import { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Compiler } from 'webpack';\n\n// Watch mode or on time build\nexport class IntlayerPlugin {\n private isWatching = false; // Flag to ensure we only start the watcher after the first build\n private configuration;\n\n constructor(configuration?: IntlayerConfig) {\n this.configuration = configuration ?? getConfiguration();\n }\n\n async apply(compiler: Compiler): Promise<void> {\n const { webpack } = compiler;\n\n const isBuild = compiler.options.mode !== 'development';\n\n const appLogger = getAppLogger(this.configuration);\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n // Specific `process.env.<KEY>` defines. webpack's DefinePlugin replaces both\n // the dot- and bracket-notation reads of a defined key, and — crucially —\n // folds them at *parse* time, which lets it dead-code-eliminate the guarded\n // dynamic `import()` chunks (e.g. the HTML/markdown renderers) for unused\n // node types. The config flags are emitted in every mode so routing/editor\n // behaviour is correct in dev too; the dictionary scan (used to prune node\n // types) only runs for production builds.\n let env: Record<string, string> = {\n ...getConfigEnvVars(this.configuration, wrapKey, wrapValue),\n };\n\n if (isBuild) {\n const dictionaries = getDictionaries(this.configuration);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out plugins:',\n unusedNodeTypes.map((key) => colorize(key, BLUE)).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shaking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n ),\n };\n }\n\n new webpack.DefinePlugin({\n // Catch-all so that any `process.env.*` read NOT folded by the specific\n // keys below still resolves to `undefined` instead of dereferencing a\n // bare `process`, which is not defined in browser bundles (e.g. Angular)\n // and throws `process is not defined`. This covers in-use node types\n // (never emitted as \"false\"), the dictionary selector when present, and\n // every read in development where the dictionary scan is skipped. Specific\n // keys (below) and host bundler defines (e.g. `process.env.NODE_ENV`) take\n // precedence over this object, so chunk-level tree shaking is preserved.\n 'process.env': '({})',\n ...env,\n }).apply(compiler);\n\n if (this.configuration.content.watch) {\n // Start watching (assuming watch is also async)\n await watch({ configuration: this.configuration });\n }\n\n compiler.hooks.beforeCompile.tapPromise('IntlayerPlugin', async () => {\n if (!this.isWatching) {\n try {\n await prepareIntlayer(this.configuration);\n this.isWatching = true;\n } catch (error) {\n appLogger(`Error in IntlayerPlugin: ${error}`, {\n level: 'error',\n });\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;AAmBA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,aAAa;CACrB,AAAQ;CAER,YAAY,eAAgC;AAC1C,OAAK,gBAAgB,iBAAiB,kBAAkB;;CAG1D,MAAM,MAAM,UAAmC;EAC7C,MAAM,EAAE,YAAY;EAEpB,MAAM,UAAU,SAAS,QAAQ,SAAS;EAE1C,MAAM,YAAY,aAAa,KAAK,cAAc;EAElD,MAAM,WAAW,QAAgB,eAAe;EAChD,MAAM,aAAa,UAAkB,IAAI,MAAM;EAS/C,IAAI,MAA8B,EAChC,GAAG,iBAAiB,KAAK,eAAe,SAAS,UAAU,EAC5D;AAED,MAAI,SAAS;GACX,MAAM,eAAe,gBAAgB,KAAK,cAAc;AAExD,OAAI,OAAO,KAAK,aAAa,CAAC,WAAW,EACvC,WAAU,2DAA2D,EACnE,WAAW,MACZ,CAAC;GAGJ,MAAM,kBAAkB,MAAM,wBAAwB,aAAa;AAEnE,OAAI,mBAAmB,gBAAgB,SAAS,EAC9C,WACE,CACE,0BACA,gBAAgB,KAAK,QAAQ,SAAS,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK,CAC7D,EACD,EACE,WAAW,MACZ,CACF;AAGH,SAAM;IACJ,GAAG;IAGH,GAAG,uBAAuB,iBAAiB,SAAS,UAAU;IAI9D,GAAG,+BACD,yBAAyB,aAAa,EACtC,SACA,UACD;IACF;;AAGH,MAAI,QAAQ,aAAa;GASvB,eAAe;GACf,GAAG;GACJ,CAAC,CAAC,MAAM,SAAS;AAElB,MAAI,KAAK,cAAc,QAAQ,MAE7B,OAAM,MAAM,EAAE,eAAe,KAAK,eAAe,CAAC;AAGpD,WAAS,MAAM,cAAc,WAAW,kBAAkB,YAAY;AACpE,OAAI,CAAC,KAAK,WACR,KAAI;AACF,UAAM,gBAAgB,KAAK,cAAc;AACzC,SAAK,aAAa;YACX,OAAO;AACd,cAAU,4BAA4B,SAAS,EAC7C,OAAO,SACR,CAAC;;IAGN"}
1
+ {"version":3,"file":"webpack-plugin.mjs","names":[],"sources":["../../src/webpack-plugin.ts"],"sourcesContent":["import { BLUE } from '@intlayer/config/colors';\nimport {\n formatDictionarySelectorEnvVar,\n formatNodeTypeToEnvVar,\n getConfigEnvVars,\n} from '@intlayer/config/envVars';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport {\n getHasDictionarySelector,\n getUnusedNodeTypesAsync,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport { watch } from '@intlayer/engine/watcher';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Compiler } from 'webpack';\n\n// Watch mode or on time build\nexport class IntlayerPlugin {\n private isWatching = false; // Flag to ensure we only start the watcher after the first build\n private configuration;\n\n constructor(configuration?: IntlayerConfig) {\n this.configuration = configuration ?? getConfiguration();\n }\n\n async apply(compiler: Compiler): Promise<void> {\n const { webpack } = compiler;\n\n const isBuild = compiler.options.mode !== 'development';\n\n const appLogger = getAppLogger(this.configuration);\n\n // Register the dictionary preparation tap *synchronously*, before any\n // `await` below. webpack does not await a plugin's async `apply`, so any\n // hook tapped after an `await` (e.g. after `watch()`) may register too late\n // — after `beforeCompile` has already fired — leaving the `.intlayer`\n // dictionaries entry unbuilt when module resolution starts and breaking the\n // build with `Can't resolve '@intlayer/dictionaries-entry'`. Tapping here\n // guarantees the entry is prepared before compilation begins.\n compiler.hooks.beforeCompile.tapPromise('IntlayerPlugin', async () => {\n if (!this.isWatching) {\n try {\n await prepareIntlayer(this.configuration);\n this.isWatching = true;\n } catch (error) {\n appLogger(`Error in IntlayerPlugin: ${error}`, {\n level: 'error',\n });\n }\n }\n });\n\n const wrapKey = (key: string) => `process.env.${key}`;\n const wrapValue = (value: string) => `\"${value}\"`;\n\n // Specific `process.env.<KEY>` defines. webpack's DefinePlugin replaces both\n // the dot- and bracket-notation reads of a defined key, and — crucially —\n // folds them at *parse* time, which lets it dead-code-eliminate the guarded\n // dynamic `import()` chunks (e.g. the HTML/markdown renderers) for unused\n // node types. The config flags are emitted in every mode so routing/editor\n // behaviour is correct in dev too; the dictionary scan (used to prune node\n // types) only runs for production builds.\n let env: Record<string, string> = {\n ...getConfigEnvVars(this.configuration, wrapKey, wrapValue),\n };\n\n if (isBuild) {\n const dictionaries = getDictionaries(this.configuration);\n\n if (Object.keys(dictionaries).length === 0) {\n appLogger('No dictionaries found. Please check your configuration.', {\n isVerbose: true,\n });\n }\n\n const unusedNodeTypes = await getUnusedNodeTypesAsync(dictionaries);\n\n if (unusedNodeTypes && unusedNodeTypes.length > 0) {\n appLogger(\n [\n 'Filtering out plugins:',\n unusedNodeTypes.map((key) => colorize(key, BLUE)).join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n }\n\n env = {\n ...env,\n\n // Tree shaking based on unused node types\n ...formatNodeTypeToEnvVar(unusedNodeTypes, wrapKey, wrapValue),\n\n // Tree shaking the dictionary selector logic\n // (collections / variants)\n ...formatDictionarySelectorEnvVar(\n getHasDictionarySelector(dictionaries),\n wrapKey,\n wrapValue\n ),\n };\n }\n\n new webpack.DefinePlugin({\n // Catch-all so that any `process.env.*` read NOT folded by the specific\n // keys below still resolves to `undefined` instead of dereferencing a\n // bare `process`, which is not defined in browser bundles (e.g. Angular)\n // and throws `process is not defined`. This covers in-use node types\n // (never emitted as \"false\"), the dictionary selector when present, and\n // every read in development where the dictionary scan is skipped. Specific\n // keys (below) and host bundler defines (e.g. `process.env.NODE_ENV`) take\n // precedence over this object, so chunk-level tree shaking is preserved.\n 'process.env': '({})',\n ...env,\n }).apply(compiler);\n\n // Only watch content declarations for the dev server. A production build is\n // a one-off compilation: starting a file watcher there serves no purpose and\n // keeps a live `fsevents`/chokidar stream open for the whole build.\n if (!isBuild && this.configuration.content.watch) {\n // Start watching (assuming watch is also async)\n await watch({ configuration: this.configuration });\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAmBA,IAAa,iBAAb,MAA4B;CAC1B,AAAQ,aAAa;CACrB,AAAQ;CAER,YAAY,eAAgC;AAC1C,OAAK,gBAAgB,iBAAiB,kBAAkB;;CAG1D,MAAM,MAAM,UAAmC;EAC7C,MAAM,EAAE,YAAY;EAEpB,MAAM,UAAU,SAAS,QAAQ,SAAS;EAE1C,MAAM,YAAY,aAAa,KAAK,cAAc;AASlD,WAAS,MAAM,cAAc,WAAW,kBAAkB,YAAY;AACpE,OAAI,CAAC,KAAK,WACR,KAAI;AACF,UAAM,gBAAgB,KAAK,cAAc;AACzC,SAAK,aAAa;YACX,OAAO;AACd,cAAU,4BAA4B,SAAS,EAC7C,OAAO,SACR,CAAC;;IAGN;EAEF,MAAM,WAAW,QAAgB,eAAe;EAChD,MAAM,aAAa,UAAkB,IAAI,MAAM;EAS/C,IAAI,MAA8B,EAChC,GAAG,iBAAiB,KAAK,eAAe,SAAS,UAAU,EAC5D;AAED,MAAI,SAAS;GACX,MAAM,eAAe,gBAAgB,KAAK,cAAc;AAExD,OAAI,OAAO,KAAK,aAAa,CAAC,WAAW,EACvC,WAAU,2DAA2D,EACnE,WAAW,MACZ,CAAC;GAGJ,MAAM,kBAAkB,MAAM,wBAAwB,aAAa;AAEnE,OAAI,mBAAmB,gBAAgB,SAAS,EAC9C,WACE,CACE,0BACA,gBAAgB,KAAK,QAAQ,SAAS,KAAK,KAAK,CAAC,CAAC,KAAK,KAAK,CAC7D,EACD,EACE,WAAW,MACZ,CACF;AAGH,SAAM;IACJ,GAAG;IAGH,GAAG,uBAAuB,iBAAiB,SAAS,UAAU;IAI9D,GAAG,+BACD,yBAAyB,aAAa,EACtC,SACA,UACD;IACF;;AAGH,MAAI,QAAQ,aAAa;GASvB,eAAe;GACf,GAAG;GACJ,CAAC,CAAC,MAAM,SAAS;AAKlB,MAAI,CAAC,WAAW,KAAK,cAAc,QAAQ,MAEzC,OAAM,MAAM,EAAE,eAAe,KAAK,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/webpack",
3
- "version": "9.0.0-canary.14",
3
+ "version": "9.0.0-canary.15",
4
4
  "private": false,
5
5
  "description": "Webpack plugin for seamless integration with Intlayer, enhancing JavaScript apps built with React, Next.js and more.",
6
6
  "keywords": [
@@ -77,10 +77,10 @@
77
77
  "watch": "webpack --config ./webpack.config.ts --watch"
78
78
  },
79
79
  "dependencies": {
80
- "@intlayer/config": "9.0.0-canary.14",
81
- "@intlayer/dictionaries-entry": "9.0.0-canary.14",
82
- "@intlayer/engine": "9.0.0-canary.14",
83
- "@intlayer/types": "9.0.0-canary.14",
80
+ "@intlayer/config": "9.0.0-canary.15",
81
+ "@intlayer/dictionaries-entry": "9.0.0-canary.15",
82
+ "@intlayer/engine": "9.0.0-canary.15",
83
+ "@intlayer/types": "9.0.0-canary.15",
84
84
  "fast-glob": "3.3.3",
85
85
  "webpack": "5.107.2",
86
86
  "webpack-dev-server": "5.2.4"