@rahul_ur/devlink-vite-plugin 1.0.0
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/package.json +28 -0
- package/src/index.d.ts +23 -0
- package/src/index.mjs +106 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rahul_ur/devlink-vite-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vite plugin that wires devlink-babel-plugin into Vite+React automatically",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.mjs",
|
|
7
|
+
"module": "src/index.mjs",
|
|
8
|
+
"types": "src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./src/index.mjs",
|
|
12
|
+
"types": "./src/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepublishOnly": "npm pack --dry-run"
|
|
21
|
+
},
|
|
22
|
+
"keywords": ["vite", "plugin", "devlink", "babel", "devtools"],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vite": ">=4.0.0",
|
|
26
|
+
"devlink-babel-plugin": ">=1.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface DevlinkPluginOptions {
|
|
2
|
+
/** Project root for data-source paths. Defaults to process.cwd() */
|
|
3
|
+
root?: string;
|
|
4
|
+
/** Attribute name injected onto JSX elements. Defaults to 'data-source' */
|
|
5
|
+
attribute?: string;
|
|
6
|
+
/** NODE_ENV values to activate in. Defaults to ['development'] */
|
|
7
|
+
envs?: string[];
|
|
8
|
+
/** Path patterns to exclude. Defaults to ['node_modules', '.test.', '.spec.', '__tests__'] */
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Vite plugin — add to plugins array in vite.config.ts */
|
|
13
|
+
export declare function devlinkVitePlugin(options?: DevlinkPluginOptions): import('vite').Plugin;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the babel plugin config tuple for use inside @vitejs/plugin-react babel options.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* react({ babel: { plugins: [devlinkBabelConfig({ root: process.cwd() })] } })
|
|
20
|
+
*/
|
|
21
|
+
export declare function devlinkBabelConfig(options?: DevlinkPluginOptions): [string, DevlinkPluginOptions] | null;
|
|
22
|
+
|
|
23
|
+
export default devlinkVitePlugin;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
const _require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* devlinkVitePlugin()
|
|
7
|
+
*
|
|
8
|
+
* Adds devlink-babel-plugin to Vite's React Babel transform automatically.
|
|
9
|
+
* Drop into vite.config.ts plugins array — no other config needed.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} options
|
|
12
|
+
* @param {string} [options.root] - Project root for data-source paths. Defaults to process.cwd()
|
|
13
|
+
* @param {string} [options.attribute] - Attribute name. Defaults to 'data-source'
|
|
14
|
+
* @param {string[]} [options.envs] - Environments to run in. Defaults to ['development']
|
|
15
|
+
* @param {string[]} [options.exclude] - Path patterns to skip
|
|
16
|
+
*/
|
|
17
|
+
export function devlinkVitePlugin(options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
root = process.cwd(),
|
|
20
|
+
attribute = 'data-source',
|
|
21
|
+
envs = ['development'],
|
|
22
|
+
exclude = ['node_modules', '.test.', '.spec.', '__tests__'],
|
|
23
|
+
} = options;
|
|
24
|
+
|
|
25
|
+
// Resolve the babel plugin path at config time
|
|
26
|
+
let pluginPath;
|
|
27
|
+
try {
|
|
28
|
+
pluginPath = _require.resolve('devlink-babel-plugin');
|
|
29
|
+
} catch {
|
|
30
|
+
// If not installed yet, warn and skip gracefully
|
|
31
|
+
console.warn(
|
|
32
|
+
'[devlink-vite-plugin] devlink-babel-plugin not found. ' +
|
|
33
|
+
'Run: npm install -D devlink-babel-plugin'
|
|
34
|
+
);
|
|
35
|
+
return { name: 'devlink-vite-plugin-noop' };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
name: 'devlink-vite-plugin',
|
|
40
|
+
|
|
41
|
+
// Only apply in development
|
|
42
|
+
apply: 'serve',
|
|
43
|
+
|
|
44
|
+
config(cfg, { mode }) {
|
|
45
|
+
// Only activate in allowed envs
|
|
46
|
+
if (!envs.includes(mode) && !envs.includes(process.env.NODE_ENV ?? 'development')) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ensure optimizeDeps doesn't try to pre-bundle source files
|
|
51
|
+
cfg.optimizeDeps = cfg.optimizeDeps ?? {};
|
|
52
|
+
cfg.optimizeDeps.exclude = [
|
|
53
|
+
...(cfg.optimizeDeps.exclude ?? []),
|
|
54
|
+
'devlink-studio',
|
|
55
|
+
'devlink-bridge',
|
|
56
|
+
'devlink-inspector',
|
|
57
|
+
'devlink-editor',
|
|
58
|
+
];
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// Hook into @vitejs/plugin-react's babel options
|
|
62
|
+
// This is the officially supported way to add babel plugins to Vite+React
|
|
63
|
+
options(opts) {
|
|
64
|
+
return opts;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the babel plugin config tuple for use inside @vitejs/plugin-react.
|
|
71
|
+
*
|
|
72
|
+
* Usage in vite.config.ts:
|
|
73
|
+
*
|
|
74
|
+
* import react from '@vitejs/plugin-react'
|
|
75
|
+
* import { devlinkBabelConfig } from 'devlink-vite-plugin'
|
|
76
|
+
*
|
|
77
|
+
* export default defineConfig({
|
|
78
|
+
* plugins: [
|
|
79
|
+
* react({
|
|
80
|
+
* babel: {
|
|
81
|
+
* plugins: [devlinkBabelConfig({ root: process.cwd() })]
|
|
82
|
+
* }
|
|
83
|
+
* })
|
|
84
|
+
* ]
|
|
85
|
+
* })
|
|
86
|
+
*/
|
|
87
|
+
export function devlinkBabelConfig(options = {}) {
|
|
88
|
+
const {
|
|
89
|
+
root = process.cwd(),
|
|
90
|
+
attribute = 'data-source',
|
|
91
|
+
envs = ['development'],
|
|
92
|
+
exclude = ['node_modules', '.test.', '.spec.', '__tests__'],
|
|
93
|
+
} = options;
|
|
94
|
+
|
|
95
|
+
let pluginPath;
|
|
96
|
+
try {
|
|
97
|
+
pluginPath = _require.resolve('devlink-babel-plugin');
|
|
98
|
+
} catch {
|
|
99
|
+
console.warn('[devlink-vite-plugin] devlink-babel-plugin not found.');
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [pluginPath, { root, attribute, envs, exclude }];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default devlinkVitePlugin;
|