@corespeed/webpack 0.1.0-beta.3 → 0.1.0-beta.4

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/dist/index.cjs CHANGED
@@ -19,11 +19,11 @@ var isCI = require('is-ci');
19
19
  var prompts = require('@clack/prompts');
20
20
  var installPkg = require('@antfu/install-pkg');
21
21
  var castArray = require('foxts/cast-array');
22
+ var path = require('node:path');
22
23
  var LightningCSS = require('lightningcss');
23
24
  var reactCompilerWebpack = require('react-compiler-webpack');
24
25
  var TerserWebpackPlugin = require('terser-webpack-plugin');
25
26
  var lightningcssLoader = require('lightningcss-loader');
26
- var path = require('node:path');
27
27
 
28
28
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
29
29
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -37,9 +37,9 @@ var WebpackBarProgressPlugin__default = /*#__PURE__*/_interopDefault(WebpackBarP
37
37
  var MiniCssExtractPlugin__default = /*#__PURE__*/_interopDefault(MiniCssExtractPlugin);
38
38
  var TsconfigPathsPlugin__default = /*#__PURE__*/_interopDefault(TsconfigPathsPlugin);
39
39
  var isCI__default = /*#__PURE__*/_interopDefault(isCI);
40
+ var path__default = /*#__PURE__*/_interopDefault(path);
40
41
  var LightningCSS__default = /*#__PURE__*/_interopDefault(LightningCSS);
41
42
  var TerserWebpackPlugin__default = /*#__PURE__*/_interopDefault(TerserWebpackPlugin);
42
- var path__default = /*#__PURE__*/_interopDefault(path);
43
43
 
44
44
  function getSupportedBrowsers(browserlists, dir, isDevelopment) {
45
45
  if (browserlists) {
@@ -291,6 +291,44 @@ const resolve = ({ cwd, lodashTreeShaking })=>async (config)=>{
291
291
  config.resolve.fallback['lodash-es/fp'] = globalRequire.resolve('lodash/fp');
292
292
  }
293
293
  }
294
+ /**
295
+ * tailwind-merge optimization
296
+ *
297
+ * webpack do not repect the order in the `conditionNames` config
298
+ * instead, it prioritize the order in the `exports` field of package.json
299
+ *
300
+ * since tailwind-merge list its CommonJS export before ESM export, webpack will
301
+ * always piroritize CommonJS version.
302
+ *
303
+ * We can use alias to force webpack to use the ESM version
304
+ */ try {
305
+ const tailwindMergeDistDir = globalRequire.resolve('tailwind-merge');
306
+ config.resolve.alias ??= {};
307
+ if (!Array.isArray(config.resolve.alias)) {
308
+ config.resolve.alias['tailwind-merge'] = path__default.default.join(tailwindMergeDistDir, '../bundle-mjs.mjs');
309
+ }
310
+ } catch {
311
+ // tailwind-merge does not exist, do nothing
312
+ }
313
+ /**
314
+ * use-sync-external-store/shim optimization
315
+ *
316
+ * React 18 and above has built-in support for useSyncExternalStore,
317
+ * no need to include shim
318
+ */ try {
319
+ const reactPackageJson = globalRequire('react/package.json');
320
+ const reactVersion = reactPackageJson.version;
321
+ const majorVersion = Number.parseInt(reactVersion.split('.')[0], 10);
322
+ if (majorVersion >= 18 || majorVersion === 0 // experimental versions
323
+ ) {
324
+ config.resolve.alias ??= {};
325
+ if (!Array.isArray(config.resolve.alias)) {
326
+ config.resolve.alias['use-sync-external-store/shim'] = 'react';
327
+ }
328
+ }
329
+ } catch {
330
+ // react does not exist, do nothing
331
+ }
294
332
  return config;
295
333
  };
296
334
 
package/dist/index.mjs CHANGED
@@ -17,11 +17,11 @@ import isCI from 'is-ci';
17
17
  import { confirm } from '@clack/prompts';
18
18
  import { installPackage } from '@antfu/install-pkg';
19
19
  import { castArray } from 'foxts/cast-array';
20
+ import path from 'node:path';
20
21
  import LightningCSS, { browserslistToTargets } from 'lightningcss';
21
22
  import { defineReactCompilerLoaderOption, reactCompilerLoader } from 'react-compiler-webpack';
22
23
  import TerserWebpackPlugin from 'terser-webpack-plugin';
23
24
  import { LightningCssMinifyPlugin } from 'lightningcss-loader';
24
- import path from 'node:path';
25
25
 
26
26
  function getSupportedBrowsers(browserlists, dir, isDevelopment) {
27
27
  if (browserlists) {
@@ -273,6 +273,44 @@ const resolve = ({ cwd, lodashTreeShaking })=>async (config)=>{
273
273
  config.resolve.fallback['lodash-es/fp'] = globalRequire.resolve('lodash/fp');
274
274
  }
275
275
  }
276
+ /**
277
+ * tailwind-merge optimization
278
+ *
279
+ * webpack do not repect the order in the `conditionNames` config
280
+ * instead, it prioritize the order in the `exports` field of package.json
281
+ *
282
+ * since tailwind-merge list its CommonJS export before ESM export, webpack will
283
+ * always piroritize CommonJS version.
284
+ *
285
+ * We can use alias to force webpack to use the ESM version
286
+ */ try {
287
+ const tailwindMergeDistDir = globalRequire.resolve('tailwind-merge');
288
+ config.resolve.alias ??= {};
289
+ if (!Array.isArray(config.resolve.alias)) {
290
+ config.resolve.alias['tailwind-merge'] = path.join(tailwindMergeDistDir, '../bundle-mjs.mjs');
291
+ }
292
+ } catch {
293
+ // tailwind-merge does not exist, do nothing
294
+ }
295
+ /**
296
+ * use-sync-external-store/shim optimization
297
+ *
298
+ * React 18 and above has built-in support for useSyncExternalStore,
299
+ * no need to include shim
300
+ */ try {
301
+ const reactPackageJson = globalRequire('react/package.json');
302
+ const reactVersion = reactPackageJson.version;
303
+ const majorVersion = Number.parseInt(reactVersion.split('.')[0], 10);
304
+ if (majorVersion >= 18 || majorVersion === 0 // experimental versions
305
+ ) {
306
+ config.resolve.alias ??= {};
307
+ if (!Array.isArray(config.resolve.alias)) {
308
+ config.resolve.alias['use-sync-external-store/shim'] = 'react';
309
+ }
310
+ }
311
+ } catch {
312
+ // react does not exist, do nothing
313
+ }
276
314
  return config;
277
315
  };
278
316
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corespeed/webpack",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "The opinionated webpack configuration for CoreSpeed projects.",
5
5
  "repository": {
6
6
  "type": "git",