@promoboxx/react-scripts-vite 0.1.23 → 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 +51 -0
- package/dist/cli.js +20 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/viteConfig.d.ts +18 -2
- package/dist/viteConfig.js +35 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,57 @@ Put this in `src/react-scripts-vite.d.ts`:
|
|
|
36
36
|
/// <reference types="@promoboxx/react-scripts-vite/dist/client" />
|
|
37
37
|
```
|
|
38
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
|
+
|
|
39
90
|
## Migrating from react-scripts
|
|
40
91
|
|
|
41
92
|
Should be very straightforward. For application code, everything should be supported out of the box.
|
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/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
|
package/dist/viteConfig.d.ts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
package/dist/viteConfig.js
CHANGED
|
@@ -3,6 +3,7 @@ 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;
|
|
6
7
|
var fs_1 = __importDefault(require("fs"));
|
|
7
8
|
var plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
|
|
8
9
|
var vite_plugin_checker_1 = __importDefault(require("vite-plugin-checker"));
|
|
@@ -10,10 +11,28 @@ var vite_plugin_env_compatible_1 = __importDefault(require("vite-plugin-env-comp
|
|
|
10
11
|
var vite_plugin_pwa_1 = require("vite-plugin-pwa");
|
|
11
12
|
var vite_plugin_svgr_1 = __importDefault(require("vite-plugin-svgr"));
|
|
12
13
|
var vite_tsconfig_paths_1 = __importDefault(require("vite-tsconfig-paths"));
|
|
13
|
-
var config_1 = require("vitest/config");
|
|
14
14
|
var ENV_PREFIX = 'REACT_APP_';
|
|
15
|
-
exports.
|
|
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 ({
|
|
16
34
|
base: process.env.PUBLIC_URL,
|
|
35
|
+
// TODO This doesn't really fit in with pluginOptions.
|
|
17
36
|
envPrefix: ENV_PREFIX,
|
|
18
37
|
build: {
|
|
19
38
|
outDir: process.env.BUILD_PATH || 'build',
|
|
@@ -24,32 +43,22 @@ exports.default = (0, config_1.defineConfig)({
|
|
|
24
43
|
},
|
|
25
44
|
plugins: [
|
|
26
45
|
// React specific.
|
|
27
|
-
(0, plugin_react_1.default)(
|
|
28
|
-
|
|
29
|
-
jsxRuntime: process.env.DISABLE_NEW_JSX_TRANSFORM === 'true'
|
|
30
|
-
? 'classic'
|
|
31
|
-
: undefined,
|
|
32
|
-
}),
|
|
33
|
-
(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),
|
|
34
48
|
// import.meta.env -> process.env
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
exports.pluginOptions.envCompatible === false
|
|
50
|
+
? null
|
|
51
|
+
: (0, vite_plugin_env_compatible_1.default)(exports.pluginOptions.envCompatible),
|
|
38
52
|
// Support TypeScript paths.
|
|
39
|
-
|
|
53
|
+
exports.pluginOptions.tsconfigPaths === false
|
|
54
|
+
? null
|
|
55
|
+
: (0, vite_tsconfig_paths_1.default)(exports.pluginOptions.tsconfigPaths),
|
|
40
56
|
// PWA.
|
|
41
|
-
(0, vite_plugin_pwa_1.VitePWA)(),
|
|
57
|
+
exports.pluginOptions.pwa === false ? null : (0, vite_plugin_pwa_1.VitePWA)(exports.pluginOptions.pwa),
|
|
42
58
|
// Check for issues.
|
|
43
|
-
process.env.NODE_ENV
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
? undefined
|
|
47
|
-
: {
|
|
48
|
-
lintCommand: "eslint --max-warnings=".concat(process.env.CI === 'true' ? 0 : -1, " \"./src/**/*.{ts,tsx,js,jsx,mjs,cjs}\""),
|
|
49
|
-
},
|
|
50
|
-
typescript: process.env.TSC_COMPILE_ON_ERROR !== 'true',
|
|
51
|
-
enableBuild: true,
|
|
52
|
-
}),
|
|
59
|
+
process.env.NODE_ENV === 'test' || exports.pluginOptions.checker === false
|
|
60
|
+
? null
|
|
61
|
+
: (0, vite_plugin_checker_1.default)(exports.pluginOptions.checker),
|
|
53
62
|
],
|
|
54
63
|
server: {
|
|
55
64
|
open: true,
|
|
@@ -71,5 +80,6 @@ exports.default = (0, config_1.defineConfig)({
|
|
|
71
80
|
environment: 'jsdom',
|
|
72
81
|
setupFiles: './src/test/setup.ts',
|
|
73
82
|
},
|
|
74
|
-
});
|
|
83
|
+
}); };
|
|
84
|
+
exports.default = viteConfig;
|
|
75
85
|
//# sourceMappingURL=viteConfig.js.map
|