@promoboxx/react-scripts-vite 0.1.30-rc.8 → 0.1.30-swap-plugins.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/README.md CHANGED
@@ -46,7 +46,6 @@ Put this in `src/react-scripts-vite.d.ts`:
46
46
  import { viteConfig, pluginOptions } from '@promoboxx/react-scripts-vite'
47
47
 
48
48
  // Setting one of the properties to `false` turns off the plugin entirely.
49
- // Not sure why you would want to though.
50
49
  pluginOptions.react = false
51
50
  pluginOptions.pwa = {
52
51
  registerType: 'autoUpdate',
@@ -72,18 +71,19 @@ export default defineConfig(async (env) => {
72
71
  // await is needed so the type isn't `UserConfig | Promise<UserConfig>`
73
72
  const config = await viteConfig(env)
74
73
 
75
- return {
76
- ...config,
77
- plugins: [
78
- // Add whatever plugins you want.
79
- YourVitePlugin(),
80
- ].concat(config.plugins),
81
- build: {
82
- ...config.build,
83
- // Turn off sourcemaps.
84
- sourcemap: false,
85
- },
74
+ config.plugins = [
75
+ ...(config.plugins || []),
76
+ // Add whatever plugins you want.
77
+ YourVitePlugin(),
78
+ ]
79
+
80
+ config.build = {
81
+ ...config.build,
82
+ // Turn off sourcemaps.
83
+ sourcemap: false,
86
84
  }
85
+
86
+ return config
87
87
  })
88
88
  ```
89
89
 
@@ -112,6 +112,6 @@ react-scripts-vite uses [Vitest](https://vitest.dev) instead of Jest. Vitest has
112
112
  The path to the test setup file has changed:
113
113
 
114
114
  ```shell
115
- mkdir -p src/tests/
115
+ mkdir -p src/test/
116
116
  mv src/setupTests.ts src/test/setup.ts
117
117
  ```
package/dist/cli.js CHANGED
@@ -1,45 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
-
4
- var _child_process = require("child_process");
5
- function main(command2, args2) {
6
- switch (command2) {
7
- case "start":
8
- spawnAndExit("./node_modules/.bin/vite", args2, {
9
- NODE_ENV: "development"
10
- });
11
- break;
12
- case "test":
13
- spawnAndExit("./node_modules/.bin/vitest", args2, {
14
- NODE_ENV: "test"
15
- });
16
- break;
17
- case "build":
18
- spawnAndExit("./node_modules/.bin/vite", ["build", ...args2], {
19
- NODE_ENV: "production"
20
- });
21
- break;
22
- default:
23
- throw new Error(`Unknown command: ${command2}`);
24
- }
25
- }
26
- function spawnAndExit(command2, args2 = [], env) {
27
- const child = (0, _child_process.spawn)(command2, args2, {
28
- stdio: "inherit",
29
- env: {
30
- ...process.env,
31
- ...env
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const child_process_1 = require("child_process");
5
+ function main(command, args) {
6
+ switch (command) {
7
+ case 'start':
8
+ spawnAndExit('./node_modules/.bin/vite', args, {
9
+ NODE_ENV: 'development',
10
+ });
11
+ break;
12
+ case 'test':
13
+ spawnAndExit('./node_modules/.bin/vitest', args, { NODE_ENV: 'test' });
14
+ break;
15
+ case 'build':
16
+ spawnAndExit('./node_modules/.bin/vite', ['build', ...args], {
17
+ NODE_ENV: 'production',
18
+ });
19
+ break;
20
+ default:
21
+ throw new Error(`Unknown command: ${command}`);
32
22
  }
33
- // shell: true,
34
- });
35
-
36
- child.on("exit", code => {
37
- process.exit(code ?? void 0);
38
- });
23
+ }
24
+ function spawnAndExit(command, args = [], env) {
25
+ const child = (0, child_process_1.spawn)(command, args, {
26
+ stdio: 'inherit',
27
+ env: {
28
+ ...process.env,
29
+ ...env,
30
+ },
31
+ // shell: true,
32
+ });
33
+ child.on('exit', (code) => {
34
+ process.exit(code ?? undefined);
35
+ });
39
36
  }
40
37
  const [
41
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- _interpreter,
43
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ // We should probably change our eslint config to ignore unused variables that
39
+ // start with an underscore. TypeScript ignores them, Rust ignores, them, it's
40
+ // been a convention for almost two decades.
41
+ // https://stackoverflow.com/a/77067927
42
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- see above
43
+ _interpreter,
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- see above
44
45
  _thisFile, command, ...args] = process.argv;
45
- main(command, args);
46
+ main(command, args);
47
+ //# sourceMappingURL=cli.js.map
package/dist/client.d.ts CHANGED
@@ -1,38 +1,5 @@
1
1
  /// <reference types="vite/client" />
2
2
  /// <reference types="vite-plugin-svgr/client" />
3
3
  /// <reference types="vitest/globals" />
4
-
5
- // https://github.com/antfu/vite-plugin-pwa/blob/951311fa811b8cee98ea5530522961f64645cd75/client.d.ts
6
- declare module 'virtual:pwa-register' {
7
- export type RegisterSWOptions = {
8
- immediate?: boolean
9
- onNeedRefresh?: () => void
10
- onOfflineReady?: () => void
11
- onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void
12
- onRegisterError?: (error: any) => void
13
- }
14
-
15
- export function registerSW(
16
- options?: RegisterSWOptions,
17
- ): (reloadPage?: boolean) => Promise<void>
18
- }
19
-
20
- // https://github.com/antfu/vite-plugin-pwa/blob/951311fa811b8cee98ea5530522961f64645cd75/client.d.ts
21
- declare module 'virtual:pwa-register/react' {
22
- // @ts-ignore ignore when react is not installed
23
- import { Dispatch, SetStateAction } from 'react'
24
-
25
- export type RegisterSWOptions = {
26
- immediate?: boolean
27
- onNeedRefresh?: () => void
28
- onOfflineReady?: () => void
29
- onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void
30
- onRegisterError?: (error: any) => void
31
- }
32
-
33
- export function useRegisterSW(options?: RegisterSWOptions): {
34
- needRefresh: [boolean, Dispatch<SetStateAction<boolean>>]
35
- offlineReady: [boolean, Dispatch<SetStateAction<boolean>>]
36
- updateServiceWorker: (reloadPage?: boolean) => Promise<void>
37
- }
38
- }
4
+ /// <reference types="vite-plugin-pwa/vanillajs" />
5
+ /// <reference types="vite-plugin-pwa/react" />
package/dist/index.js CHANGED
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "pluginOptions", {
7
- enumerable: true,
8
- get: function () {
9
- return _viteConfig.pluginOptions;
10
- }
11
- });
12
- Object.defineProperty(exports, "viteConfig", {
13
- enumerable: true,
14
- get: function () {
15
- return _viteConfig.default;
16
- }
17
- });
18
- var _viteConfig = _interopRequireWildcard(require("./viteConfig"));
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pluginOptions = exports.viteConfig = void 0;
7
+ var viteConfig_1 = require("./viteConfig");
8
+ Object.defineProperty(exports, "viteConfig", { enumerable: true, get: function () { return __importDefault(viteConfig_1).default; } });
9
+ Object.defineProperty(exports, "pluginOptions", { enumerable: true, get: function () { return viteConfig_1.pluginOptions; } });
10
+ //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
- import { Plugin } from 'vite';
1
+ import { type Plugin } from 'vite';
2
2
  /**
3
3
  * Replace env variables in index.html
4
4
  * @see https://github.com/vitejs/vite/issues/3105#issuecomment-939703781
5
5
  * @see https://vitejs.dev/guide/api-plugin.html#transformindexhtml
6
6
  */
7
- declare function replaceEnvInHtml(): Plugin;
7
+ declare function replaceEnvInHtml(): Plugin<any>;
8
8
  export default replaceEnvInHtml;
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Replace env variables in index.html
5
+ * @see https://github.com/vitejs/vite/issues/3105#issuecomment-939703781
6
+ * @see https://vitejs.dev/guide/api-plugin.html#transformindexhtml
7
+ */
7
8
  function replaceEnvInHtml() {
8
- let config = void 0;
9
- const plugin = {
10
- name: "replace-env-in-html",
11
- configResolved(resolvedConfig) {
12
- config = resolvedConfig;
13
- },
14
- transformIndexHtml: {
15
- enforce: "pre",
16
- transform(html) {
17
- return html.replace(/%(.*?)%/g, (match, envVarName) => config?.env?.[envVarName] ?? match);
18
- }
19
- }
20
- };
21
- return plugin;
9
+ let config = undefined;
10
+ const plugin = {
11
+ name: 'replace-env-in-html',
12
+ configResolved(resolvedConfig) {
13
+ config = resolvedConfig;
14
+ },
15
+ transformIndexHtml: {
16
+ order: 'pre',
17
+ handler(html) {
18
+ return html.replace(/%(.*?)%/g, (match, envVarName) => config?.env?.[envVarName] ?? match);
19
+ },
20
+ },
21
+ };
22
+ return plugin;
22
23
  }
23
- module.exports = replaceEnvInHtml;
24
+ exports.default = replaceEnvInHtml;
25
+ //# sourceMappingURL=replaceEnvInHtml.js.map
@@ -1,15 +1,14 @@
1
1
  import react from '@vitejs/plugin-react';
2
- import { UserConfigFn } from 'vite';
2
+ import { type UserConfigFn } from 'vite';
3
3
  import pluginChecker from 'vite-plugin-checker';
4
4
  import envCompatible from 'vite-plugin-environment';
5
5
  import { VitePWA } from 'vite-plugin-pwa';
6
6
  import svgr from 'vite-plugin-svgr';
7
- import tsconfigPaths from 'vite-tsconfig-paths';
8
7
  interface ReactScriptsViteOptions {
9
8
  react?: false | Parameters<typeof react>[0];
10
9
  svgr?: false | Parameters<typeof svgr>[0];
10
+ aliasHq?: false;
11
11
  envCompatible?: false | Parameters<typeof envCompatible>[1];
12
- tsconfigPaths?: false | Parameters<typeof tsconfigPaths>[0];
13
12
  pwa?: false | Parameters<typeof VitePWA>[0];
14
13
  checker: false | Parameters<typeof pluginChecker>[0];
15
14
  envPrefix?: string;
@@ -1,76 +1,93 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.pluginOptions = exports.default = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _pluginReact = _interopRequireDefault(require("@vitejs/plugin-react"));
9
- var _vitePluginChecker = _interopRequireDefault(require("vite-plugin-checker"));
10
- var _vitePluginEnvironment = _interopRequireDefault(require("vite-plugin-environment"));
11
- var _vitePluginPwa = require("vite-plugin-pwa");
12
- var _vitePluginSvgr = _interopRequireDefault(require("vite-plugin-svgr"));
13
- var _viteTsconfigPaths = _interopRequireDefault(require("vite-tsconfig-paths"));
14
- var _replaceEnvInHtml = _interopRequireDefault(require("./replaceEnvInHtml"));
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- const pluginOptions = exports.pluginOptions = {
17
- checker: {
18
- eslint: process.env.DISABLE_ESLINT_PLUGIN === "true" ? void 0 : {
19
- lintCommand: `eslint --max-warnings=${process.env.CI === "true" ? 0 : -1} "./src/**/*.{ts,tsx,js,jsx,mjs,cjs}"`
20
- },
21
- typescript: process.env.TSC_COMPILE_ON_ERROR !== "true",
22
- enableBuild: true,
23
- overlay: {
24
- initialIsOpen: false
25
- }
26
- },
27
- react: {
28
- jsxRuntime: process.env.DISABLE_NEW_JSX_TRANSFORM === "true" ? "classic" : void 0
29
- }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
4
  };
31
- const viteConfig = () => {
32
- const ENV_PREFIX = pluginOptions.envPrefix || "REACT_APP_";
33
- if (pluginOptions.envCompatible !== false) {
34
- pluginOptions.envCompatible = {
35
- prefix: ENV_PREFIX,
36
- ...pluginOptions.envCompatible
37
- };
38
- }
39
- return {
40
- base: process.env.PUBLIC_URL,
41
- envPrefix: ENV_PREFIX,
42
- build: {
43
- outDir: process.env.BUILD_PATH || "build",
44
- sourcemap: process.env.GENERATE_SOURCEMAP !== "false",
45
- assetsInlineLimit: process.env.IMAGE_INLINE_SIZE_LIMIT ? Number(process.env.IMAGE_INLINE_SIZE_LIMIT) : 1e4
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pluginOptions = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
9
+ const alias_hq_1 = __importDefault(require("alias-hq"));
10
+ const vite_plugin_checker_1 = __importDefault(require("vite-plugin-checker"));
11
+ const vite_plugin_environment_1 = __importDefault(require("vite-plugin-environment"));
12
+ const vite_plugin_pwa_1 = require("vite-plugin-pwa");
13
+ const vite_plugin_svgr_1 = __importDefault(require("vite-plugin-svgr"));
14
+ const replaceEnvInHtml_1 = __importDefault(require("./replaceEnvInHtml"));
15
+ exports.pluginOptions = {
16
+ checker: {
17
+ eslint: process.env.DISABLE_ESLINT_PLUGIN === 'true'
18
+ ? undefined
19
+ : {
20
+ lintCommand: `eslint --max-warnings=${process.env.CI === 'true' ? 0 : -1} "./src/**/*.{ts,tsx,js,jsx,mjs,cjs}"`,
21
+ },
22
+ typescript: process.env.TSC_COMPILE_ON_ERROR !== 'true',
23
+ enableBuild: true,
24
+ overlay: {
25
+ initialIsOpen: false,
26
+ },
46
27
  },
47
- plugins: [
48
- // Replace %ENVIRONMENT_VARIABLES% in .html files
49
- (0, _replaceEnvInHtml.default)(),
50
- // React specific.
51
- pluginOptions.react === false ? null : (0, _pluginReact.default)(pluginOptions.react), pluginOptions.svgr === false ? null : (0, _vitePluginSvgr.default)(pluginOptions.svgr),
52
- // import.meta.env -> process.env
53
- pluginOptions.envCompatible === false ? null : (0, _vitePluginEnvironment.default)("all", pluginOptions.envCompatible),
54
- // Support TypeScript paths.
55
- pluginOptions.tsconfigPaths === false ? null : (0, _viteTsconfigPaths.default)(pluginOptions.tsconfigPaths),
56
- // PWA.
57
- pluginOptions.pwa === false ? null : (0, _vitePluginPwa.VitePWA)(pluginOptions.pwa),
58
- // Check for issues.
59
- process.env.NODE_ENV === "test" || pluginOptions.checker === false ? null : (0, _vitePluginChecker.default)(pluginOptions.checker)],
60
- server: {
61
- open: true,
62
- host: process.env.HOST || "0.0.0.0",
63
- port: process.env.PORT ? Number(process.env.PORT) : 3e3,
64
- https: process.env.HTTPS === "true" ? {
65
- cert: process.env.SSL_CRT_FILE ? _fs.default.readFileSync(process.env.SSL_CRT_FILE) : void 0,
66
- key: process.env.SSL_KEY_FILE ? _fs.default.readFileSync(process.env.SSL_KEY_FILE) : void 0
67
- } : void 0
28
+ react: {
29
+ jsxRuntime: process.env.DISABLE_NEW_JSX_TRANSFORM === 'true' ? 'classic' : undefined,
68
30
  },
69
- test: {
70
- globals: true,
71
- environment: "jsdom",
72
- setupFiles: "./src/test/setup.ts"
31
+ };
32
+ const viteConfig = () => {
33
+ const ENV_PREFIX = exports.pluginOptions.envPrefix || 'REACT_APP_';
34
+ if (exports.pluginOptions.envCompatible !== false) {
35
+ exports.pluginOptions.envCompatible = {
36
+ prefix: ENV_PREFIX,
37
+ ...exports.pluginOptions.envCompatible,
38
+ };
73
39
  }
74
- };
40
+ return {
41
+ base: process.env.PUBLIC_URL,
42
+ envPrefix: ENV_PREFIX,
43
+ build: {
44
+ outDir: process.env.BUILD_PATH || 'build',
45
+ sourcemap: process.env.GENERATE_SOURCEMAP !== 'false',
46
+ assetsInlineLimit: process.env.IMAGE_INLINE_SIZE_LIMIT
47
+ ? Number(process.env.IMAGE_INLINE_SIZE_LIMIT)
48
+ : 10000,
49
+ },
50
+ plugins: [
51
+ // Replace %ENVIRONMENT_VARIABLES% in .html files
52
+ (0, replaceEnvInHtml_1.default)(),
53
+ // React specific.
54
+ exports.pluginOptions.react === false ? null : (0, plugin_react_1.default)(exports.pluginOptions.react),
55
+ exports.pluginOptions.svgr === false ? null : (0, vite_plugin_svgr_1.default)(exports.pluginOptions.svgr),
56
+ // import.meta.env -> process.env
57
+ exports.pluginOptions.envCompatible === false
58
+ ? null
59
+ : (0, vite_plugin_environment_1.default)('all', exports.pluginOptions.envCompatible),
60
+ // PWA.
61
+ exports.pluginOptions.pwa === false ? null : (0, vite_plugin_pwa_1.VitePWA)(exports.pluginOptions.pwa),
62
+ // Check for issues.
63
+ process.env.NODE_ENV === 'test' || exports.pluginOptions.checker === false
64
+ ? null
65
+ : (0, vite_plugin_checker_1.default)(exports.pluginOptions.checker),
66
+ ],
67
+ server: {
68
+ open: true,
69
+ host: process.env.HOST || '0.0.0.0',
70
+ port: process.env.PORT ? Number(process.env.PORT) : 3000,
71
+ https: process.env.HTTPS === 'true'
72
+ ? {
73
+ cert: process.env.SSL_CRT_FILE
74
+ ? fs_1.default.readFileSync(process.env.SSL_CRT_FILE)
75
+ : undefined,
76
+ key: process.env.SSL_KEY_FILE
77
+ ? fs_1.default.readFileSync(process.env.SSL_KEY_FILE)
78
+ : undefined,
79
+ }
80
+ : undefined,
81
+ },
82
+ test: {
83
+ globals: true,
84
+ environment: 'jsdom',
85
+ setupFiles: './src/test/setup.ts',
86
+ },
87
+ resolve: {
88
+ alias: exports.pluginOptions.aliasHq === false ? {} : alias_hq_1.default.get('rollup'),
89
+ },
90
+ };
75
91
  };
76
- module.exports = viteConfig;
92
+ exports.default = viteConfig;
93
+ //# sourceMappingURL=viteConfig.js.map
package/package.json CHANGED
@@ -1,51 +1,44 @@
1
1
  {
2
2
  "name": "@promoboxx/react-scripts-vite",
3
- "version": "0.1.30-rc.8",
3
+ "version": "0.1.30-swap-plugins.1",
4
4
  "description": "",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.mjs",
5
+ "main": "dist/index.js",
7
6
  "keywords": [],
8
7
  "repository": {
9
8
  "url": "https://github.com/promoboxx/react-scripts-vite"
10
9
  },
11
10
  "bin": {
12
11
  "react-scripts": "./dist/cli.js",
13
- "react-scripts-vite": "./dist/cli.js",
14
- "react-scripts-esm": "./dist/cli.mjs",
15
- "react-scripts-vite-esm": "./dist/cli.mjs"
12
+ "react-scripts-vite": "./dist/cli.js"
16
13
  },
17
14
  "author": "",
18
15
  "license": "ISC",
19
16
  "devDependencies": {
20
- "@promoboxx/eslint-config": "^3.0.1",
21
- "concurrently": "^8.2.2",
22
- "prettier": "^3.0.3",
23
- "typescript": "^5.2.2",
24
- "unbuild": "^2.0.0"
25
- },
26
- "exports": {
27
- ".": {
28
- "import": "./dist/index.mjs",
29
- "require": "./dist/index.js"
30
- },
31
- "./*": {
32
- "import": "./dist/*.mjs",
33
- "require": "./dist/*.js"
34
- }
17
+ "@promoboxx/eslint-config": "^3.1.0",
18
+ "prettier": "^3.1.0",
19
+ "typescript": "^5.3.2"
35
20
  },
36
21
  "dependencies": {
37
- "@vitejs/plugin-react": "^4.1.0",
38
- "eslint": "^8.50.0",
39
- "jsdom": "^22.1.0",
40
- "vite": "^4.4.9",
22
+ "@vitejs/plugin-react": "^4.2.0",
23
+ "alias-hq": "^6.2.3",
24
+ "eslint": "^8.54.0",
25
+ "jsdom": "^23.0.0",
26
+ "vite": "^5.0.2",
41
27
  "vite-plugin-checker": "^0.6.2",
42
28
  "vite-plugin-environment": "^1.1.3",
43
- "vite-plugin-pwa": "^0.16.5",
44
- "vite-plugin-svgr": "^4.0.0",
45
- "vite-tsconfig-paths": "^4.2.1",
46
- "vitest": "^0.34.5"
29
+ "vite-plugin-pwa": "^0.17.2",
30
+ "vite-plugin-svgr": "^4.2.0",
31
+ "vitest": "^0.34.6"
47
32
  },
48
33
  "files": [
49
- "dist/**/*"
34
+ "dist/cli.d.ts",
35
+ "dist/client.d.ts",
36
+ "dist/cli.js",
37
+ "dist/index.d.ts",
38
+ "dist/index.js",
39
+ "dist/replaceEnvInHtml.d.ts",
40
+ "dist/replaceEnvInHtml.js",
41
+ "dist/viteConfig.d.ts",
42
+ "dist/viteConfig.js"
50
43
  ]
51
44
  }
package/dist/cli.mjs DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawn } from "child_process";
3
- function main(command2, args2) {
4
- switch (command2) {
5
- case "start":
6
- spawnAndExit("./node_modules/.bin/vite", args2, {
7
- NODE_ENV: "development"
8
- });
9
- break;
10
- case "test":
11
- spawnAndExit("./node_modules/.bin/vitest", args2, { NODE_ENV: "test" });
12
- break;
13
- case "build":
14
- spawnAndExit("./node_modules/.bin/vite", ["build", ...args2], {
15
- NODE_ENV: "production"
16
- });
17
- break;
18
- default:
19
- throw new Error(`Unknown command: ${command2}`);
20
- }
21
- }
22
- function spawnAndExit(command2, args2 = [], env) {
23
- const child = spawn(command2, args2, {
24
- stdio: "inherit",
25
- env: {
26
- ...process.env,
27
- ...env
28
- }
29
- // shell: true,
30
- });
31
- child.on("exit", (code) => {
32
- process.exit(code ?? void 0);
33
- });
34
- }
35
- const [
36
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
- _interpreter,
38
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
- _thisFile,
40
- command,
41
- ...args
42
- ] = process.argv;
43
- main(command, args);
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- export { default as viteConfig, pluginOptions } from "./viteConfig.mjs";
@@ -1,20 +0,0 @@
1
- function replaceEnvInHtml() {
2
- let config = void 0;
3
- const plugin = {
4
- name: "replace-env-in-html",
5
- configResolved(resolvedConfig) {
6
- config = resolvedConfig;
7
- },
8
- transformIndexHtml: {
9
- enforce: "pre",
10
- transform(html) {
11
- return html.replace(
12
- /%(.*?)%/g,
13
- (match, envVarName) => config?.env?.[envVarName] ?? match
14
- );
15
- }
16
- }
17
- };
18
- return plugin;
19
- }
20
- export default replaceEnvInHtml;
@@ -1,71 +0,0 @@
1
- import fs from "fs";
2
- import react from "@vitejs/plugin-react";
3
- import pluginChecker from "vite-plugin-checker";
4
- import envCompatible from "vite-plugin-environment";
5
- import { VitePWA } from "vite-plugin-pwa";
6
- import svgr from "vite-plugin-svgr";
7
- import tsconfigPaths from "vite-tsconfig-paths";
8
- import replaceEnvInHtml from "./replaceEnvInHtml.mjs";
9
- export const pluginOptions = {
10
- checker: {
11
- eslint: process.env.DISABLE_ESLINT_PLUGIN === "true" ? void 0 : {
12
- lintCommand: `eslint --max-warnings=${process.env.CI === "true" ? 0 : -1} "./src/**/*.{ts,tsx,js,jsx,mjs,cjs}"`
13
- },
14
- typescript: process.env.TSC_COMPILE_ON_ERROR !== "true",
15
- enableBuild: true,
16
- overlay: {
17
- initialIsOpen: false
18
- }
19
- },
20
- react: {
21
- jsxRuntime: process.env.DISABLE_NEW_JSX_TRANSFORM === "true" ? "classic" : void 0
22
- }
23
- };
24
- const viteConfig = () => {
25
- const ENV_PREFIX = pluginOptions.envPrefix || "REACT_APP_";
26
- if (pluginOptions.envCompatible !== false) {
27
- pluginOptions.envCompatible = {
28
- prefix: ENV_PREFIX,
29
- ...pluginOptions.envCompatible
30
- };
31
- }
32
- return {
33
- base: process.env.PUBLIC_URL,
34
- envPrefix: ENV_PREFIX,
35
- build: {
36
- outDir: process.env.BUILD_PATH || "build",
37
- sourcemap: process.env.GENERATE_SOURCEMAP !== "false",
38
- assetsInlineLimit: process.env.IMAGE_INLINE_SIZE_LIMIT ? Number(process.env.IMAGE_INLINE_SIZE_LIMIT) : 1e4
39
- },
40
- plugins: [
41
- // Replace %ENVIRONMENT_VARIABLES% in .html files
42
- replaceEnvInHtml(),
43
- // React specific.
44
- pluginOptions.react === false ? null : react(pluginOptions.react),
45
- pluginOptions.svgr === false ? null : svgr(pluginOptions.svgr),
46
- // import.meta.env -> process.env
47
- pluginOptions.envCompatible === false ? null : envCompatible("all", pluginOptions.envCompatible),
48
- // Support TypeScript paths.
49
- pluginOptions.tsconfigPaths === false ? null : tsconfigPaths(pluginOptions.tsconfigPaths),
50
- // PWA.
51
- pluginOptions.pwa === false ? null : VitePWA(pluginOptions.pwa),
52
- // Check for issues.
53
- process.env.NODE_ENV === "test" || pluginOptions.checker === false ? null : pluginChecker(pluginOptions.checker)
54
- ],
55
- server: {
56
- open: true,
57
- host: process.env.HOST || "0.0.0.0",
58
- port: process.env.PORT ? Number(process.env.PORT) : 3e3,
59
- https: process.env.HTTPS === "true" ? {
60
- cert: process.env.SSL_CRT_FILE ? fs.readFileSync(process.env.SSL_CRT_FILE) : void 0,
61
- key: process.env.SSL_KEY_FILE ? fs.readFileSync(process.env.SSL_KEY_FILE) : void 0
62
- } : void 0
63
- },
64
- test: {
65
- globals: true,
66
- environment: "jsdom",
67
- setupFiles: "./src/test/setup.ts"
68
- }
69
- };
70
- };
71
- export default viteConfig;