@workleap/swc-configs 0.0.1 → 1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @workleap/swc-configs
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#92](https://github.com/gsoft-inc/wl-web-configs/pull/92) [`66e8f10`](https://github.com/gsoft-inc/wl-web-configs/commit/66e8f1033a987523c65fe9e61f53dac6d2e38777) Thanks [@ofrogon](https://github.com/ofrogon)! - Migrate project from GitHub organization
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#85](https://github.com/gsoft-inc/wl-web-configs/pull/85) [`bad2df7`](https://github.com/gsoft-inc/wl-web-configs/commit/bad2df75593fb70d431d73bdced653b157c50caa) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated TSUP configuration and added a new SWC config package
package/README.md CHANGED
@@ -26,50 +26,63 @@ npm install -D @workleap/swc-configs @swc/core @swc/helpers
26
26
 
27
27
  ### Dev
28
28
 
29
- Create a `swc.dev.ts` file at the root of your project:
29
+ Create a `swc.dev.js` file at the root of your project:
30
30
 
31
31
  ```
32
32
  root
33
33
  |---/src
34
- |---swc.dev.ts
34
+ |---swc.dev.js
35
+ |---webpack.dev.js
35
36
  ```
36
37
 
37
- Then, in the newly created file, import and execute the `defineDevConfig` function to return a valid SWC configuration object:
38
+ Then, in the newly created file, import and execute the `defineDevConfig` function to export a valid SWC configuration object:
38
39
 
39
40
  ```ts
40
- // swc.dev.ts
41
+ // swc.dev.js
41
42
 
42
43
  import { defineDevConfig } from "@workleap/swc-configs";
43
44
 
44
- return defineDevConfig();
45
+ export const swcConfig = defineDevConfig();
45
46
  ```
46
47
 
47
48
  Finally, install the Webpack [swc-loader](https://swc.rs/docs/usage/swc-loader) package and add the following `rule` to your Webpack configuration:
48
49
 
49
50
  ```js
50
- {
51
- test: /\.(ts|tsx)/i,
52
- exclude: /node_modules/,
53
- use: {
54
- loader: "swc-loader"
51
+ // webpack.dev.js
52
+
53
+ // @ts-check
54
+
55
+ import { swcConfig } from "./swc.dev.js";
56
+
57
+ /** @type {import("webpack").Configuration} */
58
+ export default {
59
+ module: {
60
+ rules: {
61
+ test: /\.(ts|tsx)/i,
62
+ exclude: /node_modules/,
63
+ use: {
64
+ loader: "swc-loader",
65
+ options: swcConfig
66
+ }
67
+ }
55
68
  }
56
69
  }
57
70
  ```
58
71
 
59
- > The rule declaration may vary depending of your project configuration. For example, you might change the `test` property to target ECMAScript files instead: `test: /\.(js|jsx)/i`.
72
+ > The rule declaration may vary depending of your project configuration. For example, you might want to change the `test` property to target ECMAScript files instead: `test: /\.(js|jsx)/i`.
60
73
 
61
- #### Customize the configuration
74
+ #### Customizing the configuration
62
75
 
63
- If you wish to customize the default development configuration, there a few options.
76
+ If you wish to customize the default development configuration, there are a few possibilities.
64
77
 
65
78
  ##### Use predefined options
66
79
 
67
- The `defineDevConfig` function accepts a few convivial options to customize the default SWC configuration without having to learn any [SWC specific configuration syntax](https://swc.rs/docs/configuration/swcrc) or mangling with complicated options.
80
+ The `defineDevConfig` function accepts predefined options to customize the default SWC configuration without having to learn any [SWC specific configuration syntax](https://swc.rs/docs/configuration/swcrc) or mangling with complicated configuration properties.
68
81
 
69
82
  To enable [React fast refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin), use the `fastRefresh` option:
70
83
 
71
84
  ```ts
72
- // swc.dev.ts
85
+ // swc.dev.js
73
86
 
74
87
  import { defineDevConfig } from "@workleap/swc-configs";
75
88
 
@@ -80,10 +93,10 @@ return defineDevConfig({
80
93
 
81
94
  > Don't forget to install [ReactRefreshWebpackPlugin](https://github.com/pmmmwh/react-refresh-webpack-plugin) and update your Webpack configuration accordingly.
82
95
 
83
- By default the development configuration expect to parse TypeScript code. If your project is coded with regular JavaScript (ECMAScript), use the `parser` option to tell SWC to expect regular JavaScript code rather than TypeScript code:
96
+ The development configuration expect to parse TypeScript code. If your project is coded with regular JavaScript (ECMAScript), use the `parser` option to configure SWC to parse regular JavaScript code rather than TypeScript code:
84
97
 
85
98
  ```ts
86
- // swc.dev.ts
99
+ // swc.dev.js
87
100
 
88
101
  import { defineDevConfig } from "@workleap/swc-configs";
89
102
 
@@ -92,13 +105,187 @@ return defineDevConfig({
92
105
  });
93
106
  ```
94
107
 
95
- ##### Provide a custom configuration object
108
+ ##### Manually overriding SWC configuration
109
+
110
+ Refer to the [configuration override](#configuration-override) section.
111
+
112
+ ### Build
113
+
114
+ Create a `swc.build.js` file at the root of your project:
115
+
116
+ ```
117
+ root
118
+ |---/src
119
+ |---swc.build.js
120
+ |---webpack.build.js
121
+ ```
122
+
123
+ Then, in the newly created file, import and execute the `defineBuildConfig` function to export a valid SWC configuration object:
124
+
125
+ ```ts
126
+ // swc.build.js
127
+
128
+ import { defineBuildConfig } from "@workleap/swc-configs";
129
+
130
+ export const swcConfig = defineBuildConfig();
131
+ ```
132
+
133
+ Finally, install the Webpack [swc-loader](https://swc.rs/docs/usage/swc-loader) package and add the following `rule` to your Webpack configuration:
134
+
135
+ ```js
136
+ // webpack.build.js
137
+
138
+ // @ts-check
139
+
140
+ import { swcConfig } from "./swc.build.js";
141
+
142
+ /** @type {import("webpack").Configuration} */
143
+ export default {
144
+ module: {
145
+ rules: {
146
+ test: /\.(ts|tsx)/i,
147
+ exclude: /node_modules/,
148
+ use: {
149
+ loader: "swc-loader",
150
+ options: swcConfig
151
+ }
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ #### Customizing the configuration
158
+
159
+ If you wish to customize the default build configuration, there are a few possibilities.
160
+
161
+ ##### Use predefined options
162
+
163
+ The `defineBuildConfig` function accepts predefined options to customize the default SWC configuration without having to learn any [SWC specific configuration syntax](https://swc.rs/docs/configuration/swcrc) or mangling with complicated configuration properties.
164
+
165
+ The build configuration expect to parse TypeScript code. If your project is coded with regular JavaScript (ECMAScript), use the `parser` option to configure SWC to parse regular JavaScript code rather than TypeScript code:
166
+
167
+ ```ts
168
+ // swc.build.js
169
+
170
+ import { defineBuildConfig } from "@workleap/swc-configs";
171
+
172
+ return defineBuildConfig({
173
+ parser: "ecmascript"
174
+ });
175
+ ```
176
+
177
+ ##### Manually overriding SWC configuration
178
+
179
+ Refer to the [configuration override](#configuration-override) section.
180
+
181
+ ### Jest
182
+
183
+ #### Installation
184
+
185
+ First install the following package:
186
+
187
+ **With pnpm**
188
+
189
+ ```shell
190
+ pnpm add -D @swc/jest
191
+ ```
192
+
193
+ **With yarn**
194
+
195
+ ```shell
196
+ yarn add -D @swc/jest
197
+ ```
198
+
199
+ **With npm**
200
+
201
+ ```shell
202
+ yarn add -D @swc/jest
203
+ ```
204
+
205
+ #### Usage
206
+
207
+ Create a `swc.jest.ts` file at the root of your project:
208
+
209
+ ```
210
+ root
211
+ |---/src
212
+ |---swc.jest.ts
213
+ |---jest.config.ts
214
+ ```
215
+
216
+ Then, in the newly created file, import and execute the `defineJestConfig` function to export a valid SWC configuration object:
217
+
218
+ ```ts
219
+ // swc.jest.ts
220
+
221
+ import { defineJestConfig } from "@workleap/swc-configs";
222
+
223
+ export const swcConfig = defineJestConfig();
224
+ ```
225
+
226
+ Finally, add the following Jest [code transform](https://jestjs.io/docs/code-transformation) to your `jest.config.ts` file:
227
+
228
+ ```js
229
+ // jest.config.ts
230
+
231
+ import { swcCnfig } from "./swc.jest.ts";
232
+
233
+ const config = {
234
+ transform: {
235
+ "^.+\\.(ts|tsx)$": ["@swc/jest", swcConfig as Record<string, unknown>]
236
+ }
237
+ };
238
+ ```
239
+
240
+ > The transform declaration may vary depending of your project configuration. For example, you might want to change the file extensions to target ECMAScript files instead: `^.+\\.(js|jsx)$`.
241
+
242
+ #### Customizing the configuration
243
+
244
+ If you wish to customize the default Jest configuration, there are a few possibilities.
245
+
246
+ ##### Use predefined options
247
+
248
+ The `defineJestConfig` function accepts predefined options to customize the default SWC configuration without having to learn any [SWC specific configuration syntax](https://swc.rs/docs/configuration/swcrc) or mangling with complicated configuration properties.
249
+
250
+ The default Jest configuration doesn't include React. To include React, use the `react` option:
251
+
252
+ ```ts
253
+ // swc.jest.ts
254
+
255
+ import { defineJestConfig } from "@workleap/swc-configs";
256
+
257
+ return defineJestConfig({
258
+ react: true
259
+ });
260
+ ```
261
+
262
+ The Jest configuration expect to parse TypeScript code. If your project is coded with regular JavaScript (ECMAScript), use the `parser` option to configure SWC to parse regular JavaScript code rather than TypeScript code:
263
+
264
+ ```ts
265
+ // swc.jest.ts
266
+
267
+ import { defineJestConfig } from "@workleap/swc-configs";
268
+
269
+ return defineJestConfig({
270
+ parser: "ecmascript"
271
+ });
272
+ ```
273
+
274
+ ##### Manually overriding SWC configuration
275
+
276
+ Refer to the [configuration override](#configuration-override) section.
277
+
278
+ ### Configuration override
279
+
280
+ > This documentation section will use the [Dev configuration](#dev) `defineDevConfig` function and `DefaultDevConfig` object to showcase examples but keep in mind that it also available for the [Build](#build) and [Jest](#jest) configurations.
96
281
 
97
- The `defineDevConfig` function also accepts a `configOverride` property. This property allow you to override any options of the default development configuration. It's important to note that the provided configuration object **will not** merge with the default configuration, it will override any matching properties of the default configuration.
282
+ All "define" functions accepts a `configOverride` property. This property allow the consumer to override any property of the default SWC configuration. The `configOverride` supports 2 syntaxes, a [custom object](#custom-object) and a [function](#function).
98
283
 
99
- > Prefer using [predefined options](#use-predefined-options) whenever possible.
284
+ It's important to note that with both syntaxes, the provided configuration **will not** be merged with the default configuration, it will override any matching properties of the default configuration.
100
285
 
101
- Given the following code:
286
+ #### Custom object
287
+
288
+ The easiest way to override manually the SWC config is with the object syntax:
102
289
 
103
290
  ```ts
104
291
  // swc.dev.ts
@@ -116,7 +303,7 @@ return defineDevConfig({
116
303
  });
117
304
  ```
118
305
 
119
- The whole `jsx` section of the default configuration would be overrided for:
306
+ In the previous example, the whole `jsx` section of the default configuration would be overrided for:
120
307
 
121
308
  ```js
122
309
  jsc: {
@@ -126,7 +313,7 @@ jsc: {
126
313
  }
127
314
  ```
128
315
 
129
- To extend the default configuration options rather than overriding them, use the `DefaultDevConfig` object to merge additional options with the default configuration:
316
+ While in some cases it's fine, often a consumer would prefer to extend the default configuration rather than overriding it's properties. To extend the configuration, use the `DefaultDevConfig` object to merge new properties with the default configuration properties:
130
317
 
131
318
  ```ts
132
319
  // swc.dev.ts
@@ -145,9 +332,9 @@ return defineDevConfig({
145
332
  });
146
333
  ```
147
334
 
148
- ##### Using a function to customize the final configuration object
335
+ ##### Function
149
336
 
150
- The `configOverride` property also accept a function. While there are a wide range of additional use cases that can be solved by using a function rather than an object, the main purpose of supporting a function here is to allow mixing [predefined options](#use-predefined-options) with a custom configuration object.
337
+ The `configOverride` property also accept a function. While there are a wide range of additional use cases that can be solved with a function, the main purpose of using a function here is to allow mixing **predefined options** with a **custom configuration object**.
151
338
 
152
339
  Take the following example:
153
340
 
@@ -169,13 +356,13 @@ return defineDevConfig({
169
356
  });
170
357
  ```
171
358
 
172
- The consumer wish to enable [React fast refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin) and ESM dynamic imports. That's a good idea to use the `fastRefresh` [predefined options](#use-predefined-options) to enable fast refresh. Since there are no predefined option to enable ESM dynamic imports, a custom configuration object must be provided to extend the `jsc.parser` section with the `dynamicImport` property.
359
+ In this example, the consumer wish to enable [React fast refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin) and ESM dynamic imports. That's a good idea to use the `fastRefresh` predefined options to enable fast refresh. However, since there are no predefined option to enable ESM dynamic imports, a custom configuration object must be provided to extend the `jsc.parser` section with the `dynamicImport` property.
173
360
 
174
- Given that the consumer extends the configuration rather than overriding it, we could expect that the React fast refresh configuration will be included in the final configuration.
361
+ Given that the consumer extends the configuration rather than overriding it, one could expect that the React fast refresh configuration will be included in the final configuration.
175
362
 
176
- Wrong, the React fast refresh configuration won't be included because it's not part of the `DefaultDevConfig` object.
363
+ Wrong, the React fast refresh configuration won't be included because it's not part of the `DefaultDevConfig` object that the consumer is extending.
177
364
 
178
- To extend the default development configuration and support predefined options, you must provide a function rather than an object:
365
+ To extend the default development configuration and also use predefined options, you must provide a function rather than an object:
179
366
 
180
367
  ```ts
181
368
  // swc.dev.ts
@@ -198,19 +385,13 @@ return defineDevConfig({
198
385
  });
199
386
  ```
200
387
 
201
- Using a function allow the consumer to receive as argument a configuration object derived from the `DefaultDevConfig` including any additional configuration added with [predefined options](#use-predefined-options).
202
-
203
- ### Build
204
-
205
- ### Jest
206
-
207
- ### Configuration override
388
+ Using a function allow the consumer to receive as argument a configuration object derived from the `DefaultDevConfig` object, including any additional properties added with predefined options.
208
389
 
209
390
  ## Maintainers notes
210
391
 
211
392
  ### CJS support
212
393
 
213
- To support CJS projects, the package is build for ESM and CJS formats. To support CJS, `type: "module"` has been temporary removed from the `package.json` file.
394
+ To support CJS projects, this package is build for ESM and CJS formats. To support CJS, `type: "module"` has been temporary removed from the `package.json` file.
214
395
 
215
396
  Once all our projects use ESM, CJS support can be removed.
216
397
 
@@ -0,0 +1,9 @@
1
+ import { Config } from '@swc/core';
2
+
3
+ interface SwcConfigTransformerContext {
4
+ environment: "dev" | "build" | "jest";
5
+ }
6
+ type SwcConfigTransformer = (config: Config, context: SwcConfigTransformerContext) => Config;
7
+ declare function applyTransformers(config: Config, transformers: SwcConfigTransformer[], context: SwcConfigTransformerContext): Config;
8
+
9
+ export { SwcConfigTransformer, SwcConfigTransformerContext, applyTransformers };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ // src/applyTransformers.ts
4
+ function applyTransformers(config, transformers, context) {
5
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
6
+ }
7
+
8
+ exports.applyTransformers = applyTransformers;
@@ -0,0 +1 @@
1
+ export { applyTransformers } from './chunk-3UBBOKDF.mjs';
package/dist/build.d.ts CHANGED
@@ -1,35 +1,11 @@
1
1
  import { Config } from '@swc/core';
2
- import { ConfigOverride } from './resolveOverrides.js';
2
+ import { SwcConfigTransformer } from './applyTransformers.js';
3
3
 
4
- declare const DefaultBuildConfig: {
5
- jsc: {
6
- parser: {
7
- syntax: "typescript";
8
- tsx: true;
9
- };
10
- target: "es2022";
11
- minify: {
12
- compress: true;
13
- mangle: true;
14
- };
15
- transform: {
16
- react: {
17
- runtime: "automatic";
18
- useBuiltins: true;
19
- };
20
- };
21
- externalHelpers: true;
22
- };
23
- module: {
24
- type: "es6";
25
- strict: true;
26
- ignoreDynamic: true;
27
- };
28
- };
29
4
  interface DefineBuildConfigOptions {
30
- parser?: "ecmascript";
31
- configOverride?: ConfigOverride;
5
+ browsers: any;
6
+ parser?: "ecmascript" | "typescript";
7
+ transformers?: SwcConfigTransformer[];
32
8
  }
33
- declare function defineBuildConfig({ parser, configOverride }?: DefineBuildConfigOptions): Config;
9
+ declare function defineBuildConfig(options: DefineBuildConfigOptions): Config;
34
10
 
35
- export { DefaultBuildConfig, DefineBuildConfigOptions, defineBuildConfig };
11
+ export { DefineBuildConfigOptions, defineBuildConfig };
package/dist/build.js CHANGED
@@ -1,72 +1,61 @@
1
1
  'use strict';
2
2
 
3
- // src/cloneObjectExceptFunctions.ts
4
- function cloneObjectExceptFunctions(obj) {
5
- return JSON.parse(JSON.stringify(obj));
6
- }
7
-
8
- // src/resolveOverrides.ts
9
- function resolveOverrides(config, configOverride) {
10
- if (typeof configOverride === "function") {
11
- return {
12
- ...config,
13
- ...configOverride(config)
14
- };
15
- }
16
- if (configOverride) {
17
- return {
18
- ...config,
19
- ...configOverride
20
- };
21
- }
22
- return config;
3
+ // src/applyTransformers.ts
4
+ function applyTransformers(config, transformers, context) {
5
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
23
6
  }
24
7
 
25
8
  // src/build.ts
26
- var DefaultBuildConfig = {
27
- jsc: {
28
- parser: {
29
- syntax: "typescript",
30
- tsx: true
31
- },
32
- // The output environment that the code will be compiled for.
33
- target: "es2022",
34
- // View https://swc.rs/docs/configuration/minification for options.
35
- minify: {
36
- compress: true,
37
- mangle: true
9
+ function defineBuildConfig(options) {
10
+ const {
11
+ browsers,
12
+ parser = "typescript",
13
+ transformers = []
14
+ } = options;
15
+ const config = {
16
+ jsc: {
17
+ parser: parser === "ecmascript" ? {
18
+ syntax: "ecmascript",
19
+ jsx: true
20
+ } : {
21
+ syntax: "typescript",
22
+ tsx: true
23
+ },
24
+ // The output environment that the code will be compiled for.
25
+ target: "es2022",
26
+ // View https://swc.rs/docs/configuration/minification for options.
27
+ minify: {
28
+ compress: true,
29
+ mangle: true
30
+ },
31
+ transform: {
32
+ react: {
33
+ // Use "react/jsx-runtime".
34
+ runtime: "automatic",
35
+ // Use the native "Object.assign()" instead of "_extends".
36
+ useBuiltins: true
37
+ }
38
+ },
39
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
40
+ // Requires to add "@swc/helpers" as a project dependency.
41
+ externalHelpers: true
38
42
  },
39
- transform: {
40
- react: {
41
- // Use "react/jsx-runtime".
42
- runtime: "automatic",
43
- // Use the native "Object.assign()" instead of "_extends".
44
- useBuiltins: true
45
- }
43
+ module: {
44
+ // The output module resolution system that the code will be compiled for.
45
+ type: "es6",
46
+ // Prevent SWC from exporting the `__esModule` property.
47
+ strict: true,
48
+ // Preserve dynamic imports.
49
+ ignoreDynamic: true
46
50
  },
47
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
48
- // Requires to add "@swc/helpers" as a project dependency
49
- externalHelpers: true
50
- },
51
- module: {
52
- // The output module resolution system that the code will be compiled for.
53
- type: "es6",
54
- // Prevent SWC from exporting the `__esModule` property.
55
- strict: true,
56
- // Preserve dynamic imports.
57
- ignoreDynamic: true
58
- }
59
- };
60
- function defineBuildConfig({ parser, configOverride } = {}) {
61
- const config = cloneObjectExceptFunctions(DefaultBuildConfig);
62
- if (parser === "ecmascript") {
63
- config.jsc.parser = {
64
- syntax: "ecmascript",
65
- jsx: true
66
- };
67
- }
68
- return resolveOverrides(config, configOverride);
51
+ env: {
52
+ targets: browsers
53
+ }
54
+ };
55
+ const transformedConfig = applyTransformers(config, transformers, {
56
+ environment: "build"
57
+ });
58
+ return transformedConfig;
69
59
  }
70
60
 
71
- exports.DefaultBuildConfig = DefaultBuildConfig;
72
61
  exports.defineBuildConfig = defineBuildConfig;
package/dist/build.mjs CHANGED
@@ -1,3 +1,2 @@
1
- export { DefaultBuildConfig, defineBuildConfig } from './chunk-JW562DWU.mjs';
2
- import './chunk-XCGQZSNA.mjs';
3
- import './chunk-4LXCYXR5.mjs';
1
+ export { defineBuildConfig } from './chunk-UFEY2RGG.mjs';
2
+ import './chunk-3UBBOKDF.mjs';
@@ -0,0 +1,6 @@
1
+ // src/applyTransformers.ts
2
+ function applyTransformers(config, transformers, context) {
3
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
4
+ }
5
+
6
+ export { applyTransformers };
@@ -0,0 +1,45 @@
1
+ import { applyTransformers } from './chunk-3UBBOKDF.mjs';
2
+
3
+ // src/jest.ts
4
+ function defineJestConfig(options = {}) {
5
+ const {
6
+ react = false,
7
+ parser = "typescript",
8
+ transformers = []
9
+ } = options;
10
+ const config = {
11
+ jsc: {
12
+ parser: parser === "ecmascript" ? {
13
+ syntax: "ecmascript",
14
+ jsx: react
15
+ } : {
16
+ syntax: "typescript",
17
+ tsx: react
18
+ },
19
+ // The output environment that the code will be compiled for.
20
+ target: "es2022",
21
+ transform: react ? {
22
+ react: {
23
+ // Use "react/jsx-runtime".
24
+ runtime: "automatic",
25
+ // Use the native "Object.assign()" instead of "_extends".
26
+ useBuiltins: true
27
+ }
28
+ } : void 0
29
+ },
30
+ module: {
31
+ // The output module resolution system that the code will be compiled for.
32
+ type: "es6",
33
+ // Prevent SWC from exporting the `__esModule` property.
34
+ strict: true,
35
+ // Preserve dynamic imports.
36
+ ignoreDynamic: true
37
+ }
38
+ };
39
+ const transformedConfig = applyTransformers(config, transformers, {
40
+ environment: "jest"
41
+ });
42
+ return transformedConfig;
43
+ }
44
+
45
+ export { defineJestConfig };
@@ -0,0 +1,55 @@
1
+ import { applyTransformers } from './chunk-3UBBOKDF.mjs';
2
+
3
+ // src/dev.ts
4
+ function defineDevConfig(options) {
5
+ const {
6
+ browsers,
7
+ fastRefresh = false,
8
+ parser = "typescript",
9
+ transformers = []
10
+ } = options;
11
+ const config = {
12
+ jsc: {
13
+ parser: parser === "ecmascript" ? {
14
+ syntax: "ecmascript",
15
+ jsx: true
16
+ } : {
17
+ syntax: "typescript",
18
+ tsx: true
19
+ },
20
+ // The output environment that the code will be compiled for.
21
+ target: "es2022",
22
+ transform: {
23
+ react: {
24
+ // Use "react/jsx-runtime".
25
+ runtime: "automatic",
26
+ // Use the native "Object.assign()" instead of "_extends".
27
+ useBuiltins: true,
28
+ // Enable React experimental "fast-refresh" feature.
29
+ // Also need to install @pmmmwh/react-refresh-webpack-plugin.
30
+ refresh: fastRefresh
31
+ }
32
+ },
33
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
34
+ // Requires to add "@swc/helpers" as a project dependency.
35
+ externalHelpers: true
36
+ },
37
+ module: {
38
+ // The output module resolution system that the code will be compiled for.
39
+ type: "es6",
40
+ // Prevent SWC from exporting the `__esModule` property.
41
+ strict: true,
42
+ // Preserve dynamic imports.
43
+ ignoreDynamic: true
44
+ },
45
+ env: {
46
+ targets: browsers
47
+ }
48
+ };
49
+ const transformedConfig = applyTransformers(config, transformers, {
50
+ environment: "dev"
51
+ });
52
+ return transformedConfig;
53
+ }
54
+
55
+ export { defineDevConfig };