package-build-stats 8.0.0-beta.6 → 8.0.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/bin/cli.js +5 -0
  4. package/package.json +85 -73
  5. package/src/common.types.ts +8 -10
  6. package/src/config/{index.ts → config.ts} +0 -1
  7. package/src/config/makeRspackConfig.ts +188 -0
  8. package/src/getDependencySizeTree.ts +355 -0
  9. package/src/getPackageExportSizes.ts +32 -43
  10. package/src/getPackageStats.ts +30 -78
  11. package/src/index.ts +0 -1
  12. package/src/types/is-valid-npm-name.d.ts +9 -0
  13. package/src/utils/build.utils.ts +232 -264
  14. package/src/utils/common.utils.ts +15 -148
  15. package/src/utils/exports.utils.ts +170 -251
  16. package/src/utils/installation.utils.ts +171 -65
  17. package/src/utils/telemetry.utils.ts +33 -10
  18. package/.parcelrc +0 -37
  19. package/build/common.types.d.ts +0 -29
  20. package/build/common.types.d.ts.map +0 -1
  21. package/build/common.types.js +0 -3
  22. package/build/common.types.js.map +0 -1
  23. package/build/config/index.d.ts +0 -6
  24. package/build/config/index.d.ts.map +0 -1
  25. package/build/config/index.js +0 -12
  26. package/build/config/index.js.map +0 -1
  27. package/build/errors/CustomError.d.ts +0 -43
  28. package/build/errors/CustomError.d.ts.map +0 -1
  29. package/build/errors/CustomError.js +0 -81
  30. package/build/errors/CustomError.js.map +0 -1
  31. package/build/fixed/fixed/parseReference.js +0 -5388
  32. package/build/fixed/parseReference.js +0 -5388
  33. package/build/getPackageExportSizes.d.ts +0 -20
  34. package/build/getPackageExportSizes.d.ts.map +0 -1
  35. package/build/getPackageExportSizes.js +0 -85
  36. package/build/getPackageExportSizes.js.map +0 -1
  37. package/build/getPackageStats.d.ts +0 -32
  38. package/build/getPackageStats.d.ts.map +0 -1
  39. package/build/getPackageStats.js +0 -113
  40. package/build/getPackageStats.js.map +0 -1
  41. package/build/getParseTime.d.ts +0 -9
  42. package/build/getParseTime.d.ts.map +0 -1
  43. package/build/getParseTime.js +0 -50
  44. package/build/getParseTime.js.map +0 -1
  45. package/build/index.d.ts +0 -6
  46. package/build/index.d.ts.map +0 -1
  47. package/build/index.js +0 -25
  48. package/build/index.js.map +0 -1
  49. package/build/utils/build.utils.d.ts +0 -54
  50. package/build/utils/build.utils.d.ts.map +0 -1
  51. package/build/utils/build.utils.js +0 -279
  52. package/build/utils/build.utils.js.map +0 -1
  53. package/build/utils/common.utils.d.ts +0 -41
  54. package/build/utils/common.utils.d.ts.map +0 -1
  55. package/build/utils/common.utils.js +0 -211
  56. package/build/utils/common.utils.js.map +0 -1
  57. package/build/utils/exports.utils.d.ts +0 -18
  58. package/build/utils/exports.utils.d.ts.map +0 -1
  59. package/build/utils/exports.utils.js +0 -250
  60. package/build/utils/exports.utils.js.map +0 -1
  61. package/build/utils/installation.utils.d.ts +0 -9
  62. package/build/utils/installation.utils.d.ts.map +0 -1
  63. package/build/utils/installation.utils.js +0 -140
  64. package/build/utils/installation.utils.js.map +0 -1
  65. package/build/utils/telemetry.utils.d.ts +0 -14
  66. package/build/utils/telemetry.utils.d.ts.map +0 -1
  67. package/build/utils/telemetry.utils.js +0 -114
  68. package/build/utils/telemetry.utils.js.map +0 -1
  69. package/src/errors/CustomError.d.ts +0 -42
  70. package/src/errors/CustomError.js +0 -81
  71. package/src/errors/CustomError.js.map +0 -1
  72. package/src/fixed/parseReference.js +0 -5388
  73. package/src/getParseTime.ts +0 -66
  74. package/src/typings/is-valid-npm-name.d.ts +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Shubham Kanodia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ <img src="https://img.shields.io/npm/v/package-build-stats.svg" /> <img src="https://img.shields.io/npm/l/package-build-stats.svg" /> <img src="https://img.shields.io/github/workflow/status/pastelsky/package-build-stats/CI/master"/>
2
+
3
+ This is the function that powers the core of building, minifying and gzipping of packages in bundlephobia.
4
+
5
+ ## Usage
6
+
7
+ ```js
8
+ const { getPackageStats } = require('package-build-stats')
9
+ ```
10
+
11
+ #### Building packages from npm
12
+
13
+ ##### Building the latest stable version
14
+
15
+ ```js
16
+ const results = await getPackageStats('moment')
17
+ ```
18
+
19
+ ##### Building a specific version / tag
20
+
21
+ ```js
22
+ const results = await getPackageStats('moment@2.24.0')
23
+ ```
24
+
25
+ ##### Building local packages (beta)
26
+
27
+ ```js
28
+ const results = await getPackageStats('~/dev/my-npm-package') // must have a package.json
29
+ ```
30
+
31
+ ##### Using different package managers
32
+
33
+ ```js
34
+ // Use Bun for 13x faster installs!
35
+ const results = await getPackageStats('lodash', { client: 'bun' })
36
+
37
+ // Or use pnpm
38
+ const results = await getPackageStats('lodash', { client: 'pnpm' })
39
+
40
+ // Or use yarn
41
+ const results = await getPackageStats('lodash', { client: 'yarn' })
42
+ ```
43
+
44
+ #### Passing options to the build
45
+
46
+ ```js
47
+ const results = await getBuiltPackageStats('moment', options)
48
+ ```
49
+
50
+ ##### Options
51
+
52
+ | Option | Values | Default | Description |
53
+ | ------------------ | ------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | client | `npm`, `yarn`, `pnpm`, or `bun` | `npm` | Which client to use to install package for building. **Bun is 13x faster!** |
55
+ | limitConcurrency | `true` or `false` | `false` | When using `yarn` as the client, use the network mutex to limit concurrency |
56
+ | networkConcurrency | `number` | `false` | When using `yarn` or `bun` as client, limit simultaneous installs to this number. |
57
+ | customImports | `Array<string>` | `null` | By default, the default export is used for calculating sizes. Setting this option allows calculation of package stats based on more granular top-level exports. |
58
+ | minifier | `terser` or `esbuild` | `terser` | ESbuild is faster, albeit with marginally larger file sizes |
59
+ | installTimeout | number (ms) | 30000 | Timeout for package install |
60
+
61
+ ## Listening to events
62
+
63
+ `package-build-stats` emits various lifecycle events when building a package.
64
+ You can listen to these events by subscribing to the event emitter (based on [mitt](https://github.com/developit/mitt)).
65
+
66
+ ```js
67
+ import { eventQueue } from 'package-build-stats'
68
+
69
+ // Listen to all events
70
+ eventQueue.on('*', callback)
71
+
72
+ // Listen to specific events
73
+ eventQueue.on('TASK_PACKAGE_BUILD', callback)
74
+ ```
75
+
76
+ For a list of all events, see [this](src/utils/telemetry.utils.ts).
77
+
78
+ ## Contributing
79
+
80
+ See [contributing guide.](CONTRIBUTING.md)
package/bin/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ require('esbuild-register/dist/node').register({
2
+ target: 'es2020',
3
+ })
4
+
5
+ require('./cli.ts')
package/package.json CHANGED
@@ -1,104 +1,116 @@
1
1
  {
2
2
  "name": "package-build-stats",
3
- "version": "8.0.0-beta.6",
3
+ "version": "8.0.1",
4
4
  "author": "Shubham Kanodia <shubham.kanodia10@gmail.com>",
5
5
  "repository": "https://github.com/pastelsky/package-build-stats",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org"
8
8
  },
9
9
  "license": "MIT",
10
+ "engines": {
11
+ "node": ">=20.0.0",
12
+ "npm": ">=10.0.0"
13
+ },
10
14
  "files": [
11
15
  "build",
12
- ".parcelrc",
13
16
  "src"
14
17
  ],
15
18
  "main": "build/index.js",
16
19
  "scripts": {
17
20
  "start": "ts-node --files index.js",
18
- "dev": "ts-node-dev --trace-warnings --ignore-watch ./tmp --transpile-only --files src/index.ts",
21
+ "dev": "DEBUG=bp* ts-node-dev --files index.js",
19
22
  "dev:perf": "DEBUG=bp-telemetry* ts-node-dev --files index.js",
20
- "build": "tsc --build --listEmittedFiles && cp -r src/fixed build/fixed",
21
- "build:watch": "tsc --build --watch",
22
- "prepublish": "yarn build"
23
+ "build": "tsc",
24
+ "type-check": "tsc --noEmit",
25
+ "lint": "oxlint src tests",
26
+ "lint:fix": "oxlint src tests --fix",
27
+ "format": "prettier --write '**/*.{html,js,ts,json,css,scss,jsx,flow,md,yml,yaml}'",
28
+ "format:check": "prettier --check '**/*.{html,js,ts,json,css,scss,jsx,flow,md,yml,yaml}'",
29
+ "check": "yarn type-check && yarn lint && yarn format:check",
30
+ "test": "vitest run tests/fast",
31
+ "test:all": "vitest run tests",
32
+ "test:slow": "vitest run tests/slow",
33
+ "test:watch": "vitest tests/fast",
34
+ "test:coverage": "vitest run --coverage tests/fast",
35
+ "test:ci": "yarn check && yarn test && yarn test:coverage",
36
+ "compare": "tsx scripts/index.ts",
37
+ "compare:list": "tsx scripts/index.ts list",
38
+ "compare:test": "tsx scripts/index.ts test",
39
+ "compare:top": "tsx scripts/index.ts top",
40
+ "compare:advanced": "tsx scripts/index.ts compare",
41
+ "prepublish": "rm -rf build && yarn check && tsc && yarn format"
23
42
  },
24
43
  "prettier": {
25
44
  "semi": false,
26
45
  "singleQuote": true,
27
46
  "arrowParens": "avoid"
28
47
  },
48
+ "bin": {
49
+ "package-stats": "./bin/cli.js"
50
+ },
29
51
  "devDependencies": {
30
- "@types/autoprefixer": "9.7.2",
31
- "@types/babel__code-frame": "^7",
32
- "@types/babel__traverse": "^7.14.2",
33
- "@types/enhanced-resolve": "^3.0.7",
34
- "@types/find-cache-dir": "^3",
35
- "@types/lodash": "^4.14.179",
36
- "@types/memoizee": "^0.4.7",
37
- "@types/mini-css-extract-plugin": "^2.5.1",
38
- "@types/node": "^14.18.12",
39
- "@types/node-gzip": "^1",
40
- "@types/rimraf": "^3.0.2",
52
+ "@rsdoctor/rspack-plugin": "^1.3.8",
53
+ "@types/autoprefixer": "^9.7.2",
54
+ "@types/debug": "^4.1.12",
55
+ "@types/escape-string-regexp": "^2.0.3",
56
+ "@types/lodash": "^4.17.13",
57
+ "@types/node": "^24.9.2",
58
+ "@types/pify": "^6.1.0",
59
+ "@types/rimraf": "^4.0.5",
60
+ "@types/sanitize-filename": "^1.6.3",
41
61
  "@types/semver": "^7",
42
- "@types/shortid": "^0.0.29",
43
- "@types/stats-lite": "^2.2.0",
44
- "@types/terser-webpack-plugin": "^5.0.4",
45
- "@types/webpack": "^5.28.0",
46
- "@types/write-file-webpack-plugin": "^4.5.2",
47
- "prettier": "^2.5.1",
48
- "pretty-quick": "^3.1.3",
49
- "ts-node": "^10.4.0",
50
- "ts-node-dev": "^1.1.8",
51
- "typescript": "^4.5.5"
62
+ "@types/yargs": "^17.0.34",
63
+ "@vitest/coverage-v8": "^4.0.6",
64
+ "@vitest/ui": "4.0.6",
65
+ "dotenv": "^17.2.3",
66
+ "husky": "^9.1.7",
67
+ "oxlint": "^1.25.0",
68
+ "p-series": "^2.1.0",
69
+ "prettier": "^3.6.2",
70
+ "pretty-quick": "^4.0.0",
71
+ "semver": "^7.7.3",
72
+ "ts-node": "^10.9.2",
73
+ "ts-node-dev": "^2.0.0",
74
+ "typescript": "^5.9.3",
75
+ "vitest": "4.0.6"
52
76
  },
53
77
  "dependencies": {
54
- "@babel/code-frame": "^7.16.7",
55
- "@babel/core": "^7.17.5",
56
- "@babel/parser": "^7.17.3",
57
- "@babel/traverse": "^7.17.3",
58
- "@babel/types": "^7.17.0",
59
- "@parcel/config-default": "^2.4.1",
60
- "@parcel/core": "^2.4.1",
61
- "@parcel/diagnostic": "^2.4.1",
62
- "@parcel/fs": "^2.4.1",
63
- "@parcel/node-resolver-core": "^2.4.1",
64
- "@parcel/optimizer-cssnano": "^2.4.1",
65
- "@parcel/optimizer-data-url": "^2.4.1",
66
- "@parcel/optimizer-htmlnano": "^2.4.1",
67
- "@parcel/optimizer-swc": "^2.4.1",
68
- "@parcel/plugin": "^2.4.1",
69
- "@parcel/reporter-bundle-analyzer": "^2.4.1",
70
- "@parcel/reporter-json": "^2.4.1",
71
- "@parcel/reporter-sourcemap-visualiser": "^2.4.1",
72
- "@parcel/runtime-js": "^2.4.1",
73
- "@parcel/source-map": "^2.0.2",
74
- "@parcel/transformer-js": "^2.4.1",
75
- "@parcel/transformer-less": "^2.4.1",
76
- "@parcel/transformer-raw": "^2.4.1",
77
- "@parcel/transformer-sass": "^2.4.1",
78
- "@parcel/transformer-vue": "^2.4.1",
79
- "@parcel/types": "^2.4.1",
80
- "@parcel/utils": "^2.4.1",
81
- "builtin-modules": "^3.2.0",
82
- "debug": "^4.3.3",
83
- "enhanced-resolve": "^5.9.1",
78
+ "@babel/core": "^7.28.5",
79
+ "@rspack/core": "^1.6.0",
80
+ "@swc/core": "^1.14.0",
81
+ "autoprefixer": "^9.7.6",
82
+ "css-loader": "^7.1.0",
83
+ "debug": "^4.4.3",
84
+ "esbuild": "^0.25.12",
85
+ "esbuild-register": "^3.6.0",
86
+ "escape-string-regexp": "^5.0.0",
84
87
  "fast-safe-stringify": "^2.1.1",
85
- "find-cache-dir": "^3.3.2",
88
+ "firebase-admin": "^13.6.0",
86
89
  "is-valid-npm-name": "^0.0.5",
90
+ "less": "^4.4.2",
91
+ "less-loader": "^12.2.0",
87
92
  "lodash": "^4.17.21",
88
- "memoizee": "^0.4.15",
89
- "mitt": "^2.1.0",
90
- "node-gzip": "^1.1.2",
91
- "p-all": "3",
92
- "parcel-reporter-package-build-stats": "^1.0.0",
93
- "parcel-resolver-package-build-stats": "^1.0.0",
94
- "performance-now": "^2.1.0",
95
- "rimraf": "^3.0.2",
93
+ "mitt": "^3.0.1",
94
+ "node-fetch": "^2.7.0",
95
+ "np": "^10.0.5",
96
+ "oxc-parser": "^0.96.0",
97
+ "oxc-resolver": "^11.13.0",
98
+ "oxc-walker": "^0.5.2",
99
+ "pify": "^6.1.0",
100
+ "postcss": "^8.4.0",
101
+ "postcss-loader": "^8.1.0",
102
+ "rimraf": "^6.1.0",
96
103
  "sanitize-filename": "^1.6.3",
97
- "semver": "^7.3.5",
98
- "shortid": "^2.2.16",
99
- "stats-lite": "^2.2.0",
100
- "vm2": "^3.9.5"
104
+ "sass": "^1.69.0",
105
+ "sass-loader": "^14.0.0",
106
+ "svelte": "^4.0.0",
107
+ "svelte-loader": "^3.1.0",
108
+ "terser": "^5.44.0",
109
+ "yargs": "^18.0.0"
101
110
  },
102
- "packageManager": "yarn@3.1.0",
103
- "stableVersion": "7.3.6"
104
- }
111
+ "packageManager": "yarn@4.10.3",
112
+ "resolutions": {
113
+ "semver": "^7.7.3",
114
+ "node-gyp": "^12.1.0"
115
+ }
116
+ }
@@ -1,13 +1,13 @@
1
- export type Minifier = 'esbuild' | 'terser'
1
+ type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'
2
2
 
3
- export type AllOptions = {
3
+ type AllOptions = {
4
4
  customImports?: Array<string>
5
5
  splitCustomImports?: boolean
6
6
  debug?: boolean
7
- calcParse?: boolean
7
+ minify?: boolean
8
8
  esm?: boolean
9
9
  entryFilename?: string
10
- client?: 'npm' | 'yarn'
10
+ client?: PackageManager | PackageManager[]
11
11
  limitConcurrency?: boolean
12
12
  networkConcurrency?: number
13
13
  additionalPackages?: Array<string>
@@ -17,17 +17,15 @@ export type AllOptions = {
17
17
 
18
18
  export type BuildPackageOptions = Pick<
19
19
  AllOptions,
20
- 'customImports' | 'splitCustomImports' | 'debug' | 'calcParse'
20
+ 'customImports' | 'splitCustomImports' | 'debug' | 'minify'
21
21
  > & {
22
22
  includeDependencySizes: boolean
23
- minifier: Minifier
24
23
  }
25
24
 
26
25
  export type CreateEntryPointOptions = Pick<
27
26
  AllOptions,
28
27
  'esm' | 'customImports' | 'entryFilename'
29
28
  >
30
-
31
29
  export type InstallPackageOptions = Pick<
32
30
  AllOptions,
33
31
  | 'client'
@@ -36,6 +34,7 @@ export type InstallPackageOptions = Pick<
36
34
  | 'additionalPackages'
37
35
  | 'isLocal'
38
36
  | 'installTimeout'
37
+ | 'debug'
39
38
  >
40
39
 
41
40
  export type GetPackageStatsOptions = Pick<
@@ -46,9 +45,8 @@ export type GetPackageStatsOptions = Pick<
46
45
  | 'debug'
47
46
  | 'customImports'
48
47
  | 'installTimeout'
49
- > & {
50
- minifier?: Minifier
51
- }
48
+ | 'minify'
49
+ >
52
50
 
53
51
  export type Externals = {
54
52
  externalPackages: Array<string>
@@ -4,5 +4,4 @@ import path from 'path'
4
4
 
5
5
  export default {
6
6
  tmp: path.join('/tmp', 'tmp-build'),
7
- compileConcurrency: 2,
8
7
  }
@@ -0,0 +1,188 @@
1
+ import autoprefixer from 'autoprefixer'
2
+
3
+ import escapeRegex from 'escape-string-regexp'
4
+ import type { Entry, Configuration } from '@rspack/core'
5
+ import rspack from '@rspack/core'
6
+
7
+ import { Externals } from '../common.types'
8
+
9
+ type MakeRspackConfigOptions = {
10
+ packageName: string
11
+ externals: Externals
12
+ debug?: boolean
13
+ minify?: boolean
14
+ entry: Entry
15
+ }
16
+
17
+ export default function makeRspackConfig({
18
+ packageName: _packageName,
19
+ entry,
20
+ externals,
21
+ debug: _debug,
22
+ minify = true,
23
+ }: MakeRspackConfigOptions): Configuration {
24
+ const externalsRegex = makeExternalsRegex(externals.externalPackages)
25
+ const isExternalRequest = (request: string) => {
26
+ const isPeerDep = externals.externalPackages.length
27
+ ? externalsRegex.test(request)
28
+ : false
29
+ const isBuiltIn = externals.externalBuiltIns.includes(request)
30
+ return isPeerDep || isBuiltIn
31
+ }
32
+
33
+ const configuration: Configuration = {
34
+ entry: entry,
35
+ mode: 'production',
36
+ devtool: _debug ? 'source-map' : false,
37
+ optimization: {
38
+ runtimeChunk: { name: 'runtime' },
39
+ realContentHash: false,
40
+ minimize: minify,
41
+ // Rspack automatically uses its built-in default minifiers:
42
+ // - SwcJsMinimizerRspackPlugin for JS (SWC-based, very fast)
43
+ // - LightningCssMinimizerRspackPlugin for CSS (Lightning CSS-based)
44
+ // See: https://rspack.rs/guide/optimization/production
45
+ splitChunks: {
46
+ cacheGroups: {
47
+ styles: {
48
+ name: 'main',
49
+ test: /\.css$/,
50
+ chunks: 'all',
51
+ },
52
+ },
53
+ },
54
+ },
55
+ stats: {
56
+ source: true,
57
+ modules: true,
58
+ nestedModules: true,
59
+ reasons: true,
60
+ depth: true,
61
+ chunkModules: true,
62
+ },
63
+ resolve: {
64
+ modules: ['node_modules'],
65
+ extensions: [
66
+ '.web.mjs',
67
+ '.mjs',
68
+ '.web.js',
69
+ '.js',
70
+ '.mjs',
71
+ '.json',
72
+ '.css',
73
+ '.sass',
74
+ '.scss',
75
+ ],
76
+ mainFields: ['browser', 'module', 'main', 'style'],
77
+ },
78
+ module: {
79
+ rules: [
80
+ {
81
+ type: 'javascript/auto',
82
+ test: /\.mjs$/,
83
+ use: [],
84
+ },
85
+ {
86
+ test: /\.css$/,
87
+ type: 'javascript/auto',
88
+ use: [
89
+ rspack.CssExtractRspackPlugin.loader,
90
+ require.resolve('css-loader'),
91
+ ],
92
+ },
93
+ {
94
+ test: /\.(html|svelte)$/,
95
+ use: {
96
+ loader: require.resolve('svelte-loader'),
97
+ options: {
98
+ emitCss: true,
99
+ },
100
+ },
101
+ },
102
+ // {
103
+ // test: /\.vue$/,
104
+ // loader: require.resolve('vue-loader'),
105
+ // },
106
+ {
107
+ test: /\.(scss|sass)$/,
108
+ type: 'javascript/auto',
109
+ use: [
110
+ rspack.CssExtractRspackPlugin.loader,
111
+ require.resolve('css-loader'),
112
+ {
113
+ loader: require.resolve('postcss-loader'),
114
+ options: {
115
+ postcssOptions: {
116
+ plugins: [autoprefixer()],
117
+ },
118
+ },
119
+ },
120
+ require.resolve('sass-loader'),
121
+ ],
122
+ },
123
+ {
124
+ test: /\.less$/,
125
+ type: 'javascript/auto',
126
+ use: [
127
+ rspack.CssExtractRspackPlugin.loader,
128
+ require.resolve('css-loader'),
129
+ {
130
+ loader: require.resolve('postcss-loader'),
131
+ options: {
132
+ postcssOptions: {
133
+ plugins: [
134
+ autoprefixer({
135
+ overrideBrowserslist: [
136
+ 'last 5 Chrome versions',
137
+ 'last 5 Firefox versions',
138
+ 'Safari >= 8',
139
+ 'Explorer >= 10',
140
+ 'edge >= 12',
141
+ ],
142
+ }),
143
+ ],
144
+ },
145
+ },
146
+ },
147
+ {
148
+ loader: require.resolve('less-loader'),
149
+ options: {
150
+ lessOptions: {
151
+ javascriptEnabled: true,
152
+ },
153
+ },
154
+ },
155
+ ],
156
+ },
157
+ ],
158
+ },
159
+ plugins: [
160
+ new rspack.CssExtractRspackPlugin({
161
+ filename: '[name].bundle.css',
162
+ }),
163
+ ],
164
+
165
+ node: {
166
+ global: false,
167
+ },
168
+ output: {
169
+ filename: '[name].bundle.js',
170
+ },
171
+ externals: ({ request }, callback) =>
172
+ isExternalRequest(request || '')
173
+ ? callback(undefined, 'commonjs ' + request)
174
+ : callback(undefined),
175
+ }
176
+
177
+ return configuration
178
+ }
179
+
180
+ function makeExternalsRegex(externals: string[]) {
181
+ let externalsRegex = externals
182
+ .map(dep => `^${escapeRegex(dep)}$|^${escapeRegex(dep)}\\/`)
183
+ .join('|')
184
+
185
+ externalsRegex = `(${externalsRegex})`
186
+
187
+ return new RegExp(externalsRegex)
188
+ }