@promoboxx/react-scripts-vite 0.1.21 → 0.1.24

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
@@ -8,6 +8,7 @@ An almost drop-in replacement for react-scripts, but based on Vite.
8
8
  - TypeScript `paths`
9
9
  - TypeScript type checking
10
10
  - ESLint linting
11
+ - PWA support
11
12
  - `process.env`
12
13
  - Vitest
13
14
 
@@ -35,6 +36,57 @@ Put this in `src/react-scripts-vite.d.ts`:
35
36
  /// <reference types="@promoboxx/react-scripts-vite/dist/client" />
36
37
  ```
37
38
 
39
+ ## Customization
40
+
41
+ `react-scripts-vite` exports both a `viteConfig` function and an `pluginOptions` object. The `pluginOptions` object lets you customize the included plugins. And if you'd like to add your own plugins, or change any of the vite config, you're free to do so.
42
+
43
+ ### Changing included plugin options
44
+
45
+ ```typescript
46
+ import { viteConfig, pluginOptions } from '@promoboxx/react-scripts-vite'
47
+
48
+ // Setting one of the properties to `false` turns off the plugin entirely.
49
+ // Not sure why you would want to though.
50
+ pluginOptions.react = false
51
+ pluginOptions.pwa = {
52
+ registerType: 'autoUpdate',
53
+ }
54
+
55
+ export default viteConfig
56
+ ```
57
+
58
+ ### Changing included vite config
59
+
60
+ ```typescript
61
+ import { defineConfig } from 'vite'
62
+ import { viteConfig, pluginOptions } from '@promoboxx/react-scripts-vite'
63
+
64
+ // Disable SVGR.
65
+ pluginOptions.svgr = false
66
+ // Change PWA config.
67
+ pluginOptions.pwa = {
68
+ registerType: 'autoUpdate',
69
+ }
70
+
71
+ export default defineConfig(async (env) => {
72
+ // await is needed so the type isn't `UserConfig | Promise<UserConfig>`
73
+ const config = await viteConfig(env)
74
+
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
+ },
86
+ }
87
+ })
88
+ ```
89
+
38
90
  ## Migrating from react-scripts
39
91
 
40
92
  Should be very straightforward. For application code, everything should be supported out of the box.
@@ -47,7 +99,7 @@ Vite expects your `index.html` to live at the root directory, not in `public/`
47
99
  mv public/index.html ./
48
100
  ```
49
101
 
50
- Remove any references to `%PUBLIC_URL%`. Passing `--base /some/sub/dir/` to `build` will get you the same result.
102
+ Remove any references to `%PUBLIC_URL%`, vite correctly sets the base path for you.
51
103
 
52
104
  ### Sass
53
105
 
package/dist/cli.js CHANGED
@@ -1,5 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
3
14
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
4
15
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
5
16
  if (ar || !(i in from)) {
@@ -14,22 +25,27 @@ var child_process_1 = require("child_process");
14
25
  function main(command, args) {
15
26
  switch (command) {
16
27
  case 'start':
17
- spawnAndExit('./node_modules/.bin/vite', args);
28
+ spawnAndExit('./node_modules/.bin/vite', args, {
29
+ NODE_ENV: 'development',
30
+ });
18
31
  break;
19
32
  case 'test':
20
- spawnAndExit('./node_modules/.bin/vitest', args);
33
+ spawnAndExit('./node_modules/.bin/vitest', args, { NODE_ENV: 'test' });
21
34
  break;
22
35
  case 'build':
23
- spawnAndExit('./node_modules/.bin/vite', __spreadArray(['build'], args, true));
36
+ spawnAndExit('./node_modules/.bin/vite', __spreadArray(['build'], args, true), {
37
+ NODE_ENV: 'production',
38
+ });
24
39
  break;
25
40
  default:
26
41
  throw new Error("Unknown command: ".concat(command));
27
42
  }
28
43
  }
29
- function spawnAndExit(command, args) {
44
+ function spawnAndExit(command, args, env) {
30
45
  if (args === void 0) { args = []; }
31
46
  var child = (0, child_process_1.spawn)(command, args, {
32
47
  stdio: 'inherit',
48
+ env: __assign(__assign({}, process.env), env),
33
49
  // shell: true,
34
50
  });
35
51
  child.on('exit', function (code) {
package/dist/client.d.ts CHANGED
@@ -1,3 +1,38 @@
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
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default as viteConfig } from './viteConfig';
1
+ export { default as viteConfig, pluginOptions } from './viteConfig';
package/dist/index.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.viteConfig = void 0;
6
+ exports.pluginOptions = exports.viteConfig = void 0;
7
7
  var viteConfig_1 = require("./viteConfig");
8
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; } });
9
10
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,18 @@
1
- declare const _default: import("vitest/dist/config").UserConfig;
2
- export default _default;
1
+ import react from '@vitejs/plugin-react';
2
+ import { UserConfigFn } from 'vite';
3
+ import pluginChecker from 'vite-plugin-checker';
4
+ import envCompatible from 'vite-plugin-env-compatible';
5
+ import { VitePWA } from 'vite-plugin-pwa';
6
+ import svgr from 'vite-plugin-svgr';
7
+ import tsconfigPaths from 'vite-tsconfig-paths';
8
+ interface ReactScriptsViteOptions {
9
+ react?: false | Parameters<typeof react>[0];
10
+ svgr?: false | Parameters<typeof svgr>[0];
11
+ envCompatible?: false | Parameters<typeof envCompatible>[0];
12
+ tsconfigPaths?: false | Parameters<typeof tsconfigPaths>[0];
13
+ pwa?: false | Parameters<typeof VitePWA>[0];
14
+ checker: false | Parameters<typeof pluginChecker>[0];
15
+ }
16
+ export declare const pluginOptions: ReactScriptsViteOptions;
17
+ declare const viteConfig: UserConfigFn;
18
+ export default viteConfig;
@@ -3,43 +3,83 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pluginOptions = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
6
8
  var plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
7
9
  var vite_plugin_checker_1 = __importDefault(require("vite-plugin-checker"));
8
10
  var vite_plugin_env_compatible_1 = __importDefault(require("vite-plugin-env-compatible"));
11
+ var vite_plugin_pwa_1 = require("vite-plugin-pwa");
9
12
  var vite_plugin_svgr_1 = __importDefault(require("vite-plugin-svgr"));
10
13
  var vite_tsconfig_paths_1 = __importDefault(require("vite-tsconfig-paths"));
11
- var config_1 = require("vitest/config");
12
- exports.default = (0, config_1.defineConfig)({
14
+ var ENV_PREFIX = 'REACT_APP_';
15
+ exports.pluginOptions = {
16
+ checker: {
17
+ eslint: process.env.DISABLE_ESLINT_PLUGIN === 'true'
18
+ ? undefined
19
+ : {
20
+ lintCommand: "eslint --max-warnings=".concat(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
+ },
25
+ envCompatible: {
26
+ prefix: ENV_PREFIX,
27
+ },
28
+ react: {
29
+ fastRefresh: process.env.FAST_REFRESH !== 'false',
30
+ jsxRuntime: process.env.DISABLE_NEW_JSX_TRANSFORM === 'true' ? 'classic' : undefined,
31
+ },
32
+ };
33
+ var viteConfig = function () { return ({
34
+ base: process.env.PUBLIC_URL,
35
+ // TODO This doesn't really fit in with pluginOptions.
36
+ envPrefix: ENV_PREFIX,
13
37
  build: {
14
- outDir: 'build',
15
- sourcemap: true,
38
+ outDir: process.env.BUILD_PATH || 'build',
39
+ sourcemap: process.env.GENERATE_SOURCEMAP !== 'false',
40
+ assetsInlineLimit: process.env.IMAGE_INLINE_SIZE_LIMIT
41
+ ? Number(process.env.IMAGE_INLINE_SIZE_LIMIT)
42
+ : 10000,
16
43
  },
17
44
  plugins: [
18
45
  // React specific.
19
- (0, plugin_react_1.default)(),
20
- (0, vite_plugin_svgr_1.default)(),
46
+ exports.pluginOptions.react === false ? null : (0, plugin_react_1.default)(exports.pluginOptions.react),
47
+ exports.pluginOptions.svgr === false ? null : (0, vite_plugin_svgr_1.default)(exports.pluginOptions.svgr),
21
48
  // import.meta.env -> process.env
22
- (0, vite_plugin_env_compatible_1.default)(),
49
+ exports.pluginOptions.envCompatible === false
50
+ ? null
51
+ : (0, vite_plugin_env_compatible_1.default)(exports.pluginOptions.envCompatible),
23
52
  // Support TypeScript paths.
24
- (0, vite_tsconfig_paths_1.default)(),
53
+ exports.pluginOptions.tsconfigPaths === false
54
+ ? null
55
+ : (0, vite_tsconfig_paths_1.default)(exports.pluginOptions.tsconfigPaths),
56
+ // PWA.
57
+ exports.pluginOptions.pwa === false ? null : (0, vite_plugin_pwa_1.VitePWA)(exports.pluginOptions.pwa),
25
58
  // Check for issues.
26
- process.env.NODE_ENV !== 'test' &&
27
- (0, vite_plugin_checker_1.default)({
28
- eslint: {
29
- lintCommand: "eslint --max-warnings=".concat(process.env.CI === 'true' ? 0 : -1, " \"./src/**/*.{ts,tsx,js,jsx,mjs,cjs}\""),
30
- },
31
- typescript: true,
32
- enableBuild: true,
33
- }),
59
+ process.env.NODE_ENV === 'test' || exports.pluginOptions.checker === false
60
+ ? null
61
+ : (0, vite_plugin_checker_1.default)(exports.pluginOptions.checker),
34
62
  ],
35
63
  server: {
36
64
  open: true,
37
- host: '0.0.0.0',
65
+ host: process.env.HOST || '0.0.0.0',
66
+ port: process.env.PORT ? Number(process.env.PORT) : 3000,
67
+ https: process.env.HTTPS === 'true'
68
+ ? {
69
+ cert: process.env.SSL_CRT_FILE
70
+ ? fs_1.default.readFileSync(process.env.SSL_CRT_FILE)
71
+ : undefined,
72
+ key: process.env.SSL_KEY_FILE
73
+ ? fs_1.default.readFileSync(process.env.SSL_KEY_FILE)
74
+ : undefined,
75
+ }
76
+ : undefined,
38
77
  },
39
78
  test: {
40
79
  globals: true,
41
80
  environment: 'jsdom',
42
81
  setupFiles: './src/test/setup.ts',
43
82
  },
44
- });
83
+ }); };
84
+ exports.default = viteConfig;
45
85
  //# sourceMappingURL=viteConfig.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promoboxx/react-scripts-vite",
3
- "version": "0.1.21",
3
+ "version": "0.1.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [],
@@ -25,6 +25,7 @@
25
25
  "vite": "^2.8.4",
26
26
  "vite-plugin-checker": "^0.4.2",
27
27
  "vite-plugin-env-compatible": "^1.1.1",
28
+ "vite-plugin-pwa": "^0.11.13",
28
29
  "vite-plugin-svgr": "^1.0.1",
29
30
  "vite-tsconfig-paths": "^3.4.1",
30
31
  "vitest": "^0.5.5"