@adonisjs/vite 0.0.1-0 → 0.0.1-10
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/build/configure.d.ts +3 -1
- package/build/configure.js +24 -10
- package/build/index.d.ts +1 -1
- package/build/index.js +9 -0
- package/build/providers/vite_provider.d.ts +14 -4
- package/build/providers/vite_provider.js +82 -36
- package/build/services/vite.d.ts +1 -2
- package/build/services/vite.js +12 -0
- package/build/src/backend/debug.d.ts +3 -0
- package/{src/backend/types/extended.ts → build/src/backend/debug.js} +2 -11
- package/build/src/backend/define_config.d.ts +5 -0
- package/build/src/backend/define_config.js +19 -0
- package/build/src/backend/edge_plugin_vite.d.ts +7 -0
- package/build/src/backend/edge_plugin_vite.js +86 -0
- package/build/src/backend/types/extended.d.ts +8 -1
- package/build/src/backend/types/extended.js +8 -0
- package/build/src/backend/types/main.d.ts +57 -1
- package/build/src/backend/types/main.js +8 -0
- package/build/src/backend/utils.d.ts +7 -1
- package/build/src/backend/utils.js +29 -0
- package/build/src/backend/vite.d.ts +33 -13
- package/build/src/backend/vite.js +206 -113
- package/build/src/{vite_plugin → client}/config.d.ts +7 -2
- package/build/src/{vite_plugin → client}/config.js +28 -2
- package/build/src/{vite_plugin → client}/config_resolver.d.ts +13 -2
- package/build/src/{vite_plugin → client}/config_resolver.js +22 -3
- package/build/src/{vite_plugin → client}/helpers/inertia.d.ts +3 -1
- package/build/src/{vite_plugin → client}/helpers/inertia.js +11 -0
- package/build/src/{vite_plugin → client}/hot_file.d.ts +6 -1
- package/build/src/{vite_plugin → client}/hot_file.js +21 -2
- package/build/src/client/main.d.ts +6 -0
- package/build/src/client/main.js +24 -0
- package/build/src/client/types.d.ts +35 -0
- package/build/src/client/types.js +9 -0
- package/build/src/{vite_plugin → client}/utils.d.ts +7 -2
- package/build/src/{vite_plugin → client}/utils.js +14 -0
- package/build/stubs/client_config.stub +22 -0
- package/build/stubs/config.stub +21 -0
- package/build/stubs/index.d.ts +0 -1
- package/build/stubs/index.js +2 -2
- package/build/stubs/js_entrypoint.stub +4 -0
- package/package.json +74 -81
- package/build/configure.d.ts.map +0 -1
- package/build/index.d.ts.map +0 -1
- package/build/providers/vite_provider.d.ts.map +0 -1
- package/build/services/vite.d.ts.map +0 -1
- package/build/src/backend/types/extended.d.ts.map +0 -1
- package/build/src/backend/types/main.d.ts.map +0 -1
- package/build/src/backend/utils.d.ts.map +0 -1
- package/build/src/backend/vite.d.ts.map +0 -1
- package/build/src/vite_plugin/config.d.ts.map +0 -1
- package/build/src/vite_plugin/config_resolver.d.ts.map +0 -1
- package/build/src/vite_plugin/helpers/inertia.d.ts.map +0 -1
- package/build/src/vite_plugin/hot_file.d.ts.map +0 -1
- package/build/src/vite_plugin/index.d.ts +0 -4
- package/build/src/vite_plugin/index.d.ts.map +0 -1
- package/build/src/vite_plugin/index.js +0 -16
- package/build/src/vite_plugin/types/index.d.ts +0 -10
- package/build/src/vite_plugin/types/index.d.ts.map +0 -1
- package/build/src/vite_plugin/types/index.js +0 -1
- package/build/src/vite_plugin/utils.d.ts.map +0 -1
- package/build/stubs/index.d.ts.map +0 -1
- package/build/stubs/vite/vite_config.stub +0 -14
- package/configure.ts +0 -30
- package/index.ts +0 -15
- package/providers/vite_provider.ts +0 -89
- package/services/vite.ts +0 -23
- package/src/backend/types/main.ts +0 -31
- package/src/backend/utils.ts +0 -19
- package/src/backend/vite.ts +0 -367
- package/src/vite_plugin/config.ts +0 -97
- package/src/vite_plugin/config_resolver.ts +0 -62
- package/src/vite_plugin/helpers/inertia.ts +0 -27
- package/src/vite_plugin/hot_file.ts +0 -59
- package/src/vite_plugin/index.ts +0 -38
- package/src/vite_plugin/types/index.ts +0 -56
- package/src/vite_plugin/utils.ts +0 -40
package/build/configure.d.ts
CHANGED
package/build/configure.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Configures the package
|
|
11
|
+
*/
|
|
3
12
|
export async function configure(command) {
|
|
4
|
-
|
|
5
|
-
await command.publishStub('
|
|
6
|
-
|
|
13
|
+
await command.publishStub('config.stub');
|
|
14
|
+
await command.publishStub('client_config.stub');
|
|
15
|
+
await command.publishStub('js_entrypoint.stub');
|
|
16
|
+
const codemods = await command.createCodemods();
|
|
17
|
+
await codemods.updateRcFile((rcFile) => {
|
|
18
|
+
rcFile.addProvider('@adonisjs/vite/vite_provider');
|
|
19
|
+
rcFile.addMetaFile('public/**', false);
|
|
7
20
|
});
|
|
8
|
-
await command.
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
if (await command.prompt.confirm('Do you want to install "vite"?')) {
|
|
22
|
+
await command.installPackages([{ name: 'vite', isDevDependency: true }]);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
command.listPackagesToInstall([{ name: 'vite', isDevDependency: true }]);
|
|
26
|
+
}
|
|
13
27
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import './src/backend/types/extended.js';
|
|
|
2
2
|
export { configure } from './configure.js';
|
|
3
3
|
export { stubsRoot } from './stubs/index.js';
|
|
4
4
|
export { Vite } from './src/backend/vite.js';
|
|
5
|
-
|
|
5
|
+
export { defineConfig } from './src/backend/define_config.js';
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import './src/backend/types/extended.js';
|
|
2
10
|
export { configure } from './configure.js';
|
|
3
11
|
export { stubsRoot } from './stubs/index.js';
|
|
4
12
|
export { Vite } from './src/backend/vite.js';
|
|
13
|
+
export { defineConfig } from './src/backend/define_config.js';
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { ApplicationService } from '@adonisjs/core/types';
|
|
1
|
+
import type { Edge } from 'edge.js';
|
|
2
|
+
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
|
+
import type { cspKeywords } from '@adonisjs/shield';
|
|
3
4
|
export default class ViteServiceProvider {
|
|
4
|
-
#private;
|
|
5
5
|
protected app: ApplicationService;
|
|
6
6
|
constructor(app: ApplicationService);
|
|
7
|
+
/**
|
|
8
|
+
* Returns edge when it's installed
|
|
9
|
+
*/
|
|
10
|
+
protected getEdge(): Promise<Edge | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns shield CSP keywords, when the package is installed
|
|
13
|
+
*/
|
|
14
|
+
protected getShieldCspKeywords(): Promise<typeof cspKeywords | null>;
|
|
7
15
|
register(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Extending edge
|
|
18
|
+
*/
|
|
8
19
|
boot(): Promise<void>;
|
|
9
20
|
}
|
|
10
|
-
//# sourceMappingURL=vite_provider.d.ts.map
|
|
@@ -1,48 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import debug from '../src/backend/debug.js';
|
|
4
10
|
export default class ViteServiceProvider {
|
|
5
11
|
app;
|
|
6
12
|
constructor(app) {
|
|
7
13
|
this.app = app;
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
|
|
23
|
-
const entrypoints = parser.utils.stringify(parsed);
|
|
24
|
-
buffer.outputExpression(`state.vite.generateEntryPointsTags(${entrypoints})`, token.filename, token.loc.start.line, false);
|
|
25
|
-
},
|
|
26
|
-
});
|
|
15
|
+
/**
|
|
16
|
+
* Returns edge when it's installed
|
|
17
|
+
*/
|
|
18
|
+
async getEdge() {
|
|
19
|
+
try {
|
|
20
|
+
const { default: edge } = await import('edge.js');
|
|
21
|
+
debug('Detected edge.js package. Adding Vite primitives to it');
|
|
22
|
+
return edge;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns shield CSP keywords, when the package is installed
|
|
30
|
+
*/
|
|
31
|
+
async getShieldCspKeywords() {
|
|
32
|
+
try {
|
|
33
|
+
const { cspKeywords } = await import('@adonisjs/shield');
|
|
34
|
+
debug('Detected @adonisjs/shield package. Adding Vite keywords for CSP policy');
|
|
35
|
+
return cspKeywords;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
register() {
|
|
39
|
-
this.app.container.singleton('vite', async () =>
|
|
42
|
+
this.app.container.singleton('vite', async () => {
|
|
43
|
+
const { Vite } = await import('../src/backend/vite.js');
|
|
44
|
+
const config = this.app.config.get('vite');
|
|
45
|
+
return new Vite({
|
|
46
|
+
...config,
|
|
47
|
+
buildDirectory: this.app.makePath(config.buildDirectory || 'public/build'),
|
|
48
|
+
hotFile: this.app.makePath(config.hotFile || 'public/build/hot.json'),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
40
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Extending edge
|
|
54
|
+
*/
|
|
41
55
|
async boot() {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
const edge = await this.getEdge();
|
|
57
|
+
if (edge) {
|
|
58
|
+
const vite = await this.app.container.make('vite');
|
|
59
|
+
const { edgePluginVite } = await import('../src/backend/edge_plugin_vite.js');
|
|
60
|
+
edge.use(edgePluginVite(vite));
|
|
61
|
+
}
|
|
62
|
+
const cspKeywords = await this.getShieldCspKeywords();
|
|
63
|
+
if (cspKeywords) {
|
|
64
|
+
const vite = await this.app.container.make('vite');
|
|
65
|
+
/**
|
|
66
|
+
* Registering the @viteUrl keyword for CSP directives.
|
|
67
|
+
* Returns http URL to the dev or the CDN server, otherwise
|
|
68
|
+
* an empty string
|
|
69
|
+
*/
|
|
70
|
+
cspKeywords.register('@viteUrl', function () {
|
|
71
|
+
const assetsURL = vite.assetsUrl();
|
|
72
|
+
if (!assetsURL || !assetsURL.startsWith('http://') || assetsURL.startsWith('https://')) {
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
return assetsURL;
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Registering the @viteDevUrl keyword for the CSP directives.
|
|
79
|
+
* Returns the dev server URL in development and empty string
|
|
80
|
+
* in prod
|
|
81
|
+
*/
|
|
82
|
+
cspKeywords.register('@viteDevUrl', function () {
|
|
83
|
+
return vite.devUrl();
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Registering the @viteHmrUrl keyword for the CSP directives.
|
|
87
|
+
* Returns the Websocket URL for the HMR server
|
|
88
|
+
*/
|
|
89
|
+
cspKeywords.register('@viteHmrUrl', function () {
|
|
90
|
+
return vite.devUrl().replace('http://', 'ws://').replace('https://', 'wss://');
|
|
91
|
+
});
|
|
92
|
+
}
|
|
47
93
|
}
|
|
48
94
|
}
|
package/build/services/vite.d.ts
CHANGED
package/build/services/vite.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import app from '@adonisjs/core/services/app';
|
|
2
10
|
let vite;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a singleton instance of Vite class
|
|
13
|
+
* from the container
|
|
14
|
+
*/
|
|
3
15
|
await app.booted(async () => {
|
|
4
16
|
vite = await app.container.make('vite');
|
|
5
17
|
});
|
|
@@ -6,14 +6,5 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Extend the container bindings
|
|
14
|
-
*/
|
|
15
|
-
declare module '@adonisjs/core/types' {
|
|
16
|
-
interface ContainerBindings {
|
|
17
|
-
vite: Vite
|
|
18
|
-
}
|
|
19
|
-
}
|
|
9
|
+
import { debuglog } from 'node:util';
|
|
10
|
+
export default debuglog('adonisjs:vite');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Define the backend config for resolving vite assets
|
|
11
|
+
*/
|
|
12
|
+
export function defineConfig(config) {
|
|
13
|
+
return {
|
|
14
|
+
buildDirectory: 'public/assets',
|
|
15
|
+
hotFile: 'public/assets/hot.json',
|
|
16
|
+
assetsUrl: '/assets',
|
|
17
|
+
...config,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import { EdgeError } from 'edge-error';
|
|
10
|
+
import debug from './debug.js';
|
|
11
|
+
/**
|
|
12
|
+
* The edge plugin for vite to share vite service with edge
|
|
13
|
+
* and register custom tags
|
|
14
|
+
*/
|
|
15
|
+
export const edgePluginVite = (vite) => {
|
|
16
|
+
return (edge) => {
|
|
17
|
+
debug('sharing vite and asset globals with edge');
|
|
18
|
+
edge.global('vite', vite);
|
|
19
|
+
edge.global('asset', vite.assetPath.bind(vite));
|
|
20
|
+
debug('registering vite tags with edge');
|
|
21
|
+
edge.registerTag({
|
|
22
|
+
tagName: 'viteReactRefresh',
|
|
23
|
+
seekable: true,
|
|
24
|
+
block: false,
|
|
25
|
+
compile(parser, buffer, token) {
|
|
26
|
+
let attributes = '';
|
|
27
|
+
if (token.properties.jsArg.trim()) {
|
|
28
|
+
/**
|
|
29
|
+
* Converting a single argument to a SequenceExpression so that we
|
|
30
|
+
* work around the following edge cases.
|
|
31
|
+
*
|
|
32
|
+
* - If someone passes an object literal to the tag, ie { nonce: 'foo' }
|
|
33
|
+
* it will be parsed as a LabeledStatement and not an object.
|
|
34
|
+
* - If we wrap the object literal inside parenthesis, ie ({nonce: 'foo'})
|
|
35
|
+
* then we will end up messing other expressions like a variable reference
|
|
36
|
+
* , or a member expression and so on.
|
|
37
|
+
* - So the best bet is to convert user supplied argument to a sequence expression
|
|
38
|
+
* and hence ignore it during stringification.
|
|
39
|
+
*/
|
|
40
|
+
const jsArg = `a,${token.properties.jsArg}`;
|
|
41
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(jsArg, token.loc, token.filename), token.filename, parser);
|
|
42
|
+
attributes = parser.utils.stringify(parsed.expressions[1]);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get HMR script
|
|
46
|
+
*/
|
|
47
|
+
buffer.writeExpression(`const __vite_hmr_script = state.vite.getReactHmrScript(${attributes})`, token.filename, token.loc.start.line);
|
|
48
|
+
/**
|
|
49
|
+
* Check if the script exists (only in hot mode)
|
|
50
|
+
*/
|
|
51
|
+
buffer.writeStatement('if(__vite_hmr_script) {', token.filename, token.loc.start.line);
|
|
52
|
+
/**
|
|
53
|
+
* Write output
|
|
54
|
+
*/
|
|
55
|
+
buffer.outputExpression(`__vite_hmr_script.toString()`, token.filename, token.loc.start.line, false);
|
|
56
|
+
/**
|
|
57
|
+
* Close if block
|
|
58
|
+
*/
|
|
59
|
+
buffer.writeStatement('}', token.filename, token.loc.start.line);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
edge.registerTag({
|
|
63
|
+
tagName: 'vite',
|
|
64
|
+
seekable: true,
|
|
65
|
+
block: false,
|
|
66
|
+
compile(parser, buffer, token) {
|
|
67
|
+
/**
|
|
68
|
+
* Ensure an argument is defined
|
|
69
|
+
*/
|
|
70
|
+
if (!token.properties.jsArg.trim()) {
|
|
71
|
+
throw new EdgeError('Missing entrypoint name', 'E_RUNTIME_EXCEPTION', {
|
|
72
|
+
filename: token.filename,
|
|
73
|
+
line: token.loc.start.line,
|
|
74
|
+
col: token.loc.start.col,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
|
|
78
|
+
const entrypoints = parser.utils.stringify(parsed);
|
|
79
|
+
const methodCall = parsed.type === 'SequenceExpression'
|
|
80
|
+
? `generateEntryPointsTags${entrypoints}`
|
|
81
|
+
: `generateEntryPointsTags(${entrypoints})`;
|
|
82
|
+
buffer.outputExpression(`state.vite.${methodCall}.join('\\n')`, token.filename, token.loc.start.line, false);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Vite } from '../vite.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extend the container bindings
|
|
4
|
+
*/
|
|
2
5
|
declare module '@adonisjs/core/types' {
|
|
3
6
|
interface ContainerBindings {
|
|
4
7
|
vite: Vite;
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
declare module 'vite' {
|
|
11
|
+
interface ManifestChunk {
|
|
12
|
+
integrity: string;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,9 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contents of the hotfile
|
|
3
|
+
*/
|
|
1
4
|
export type HotFile = {
|
|
2
5
|
url: string;
|
|
3
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Parameters passed to the setAttributes callback
|
|
9
|
+
*/
|
|
4
10
|
export type SetAttributesCallbackParams = {
|
|
5
11
|
src: string;
|
|
6
12
|
url: string;
|
|
7
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Attributes to be set on the script/style tags.
|
|
16
|
+
* Can be either a record or a callback that returns a record.
|
|
17
|
+
*/
|
|
8
18
|
export type SetAttributes = Record<string, string | boolean> | ((params: SetAttributesCallbackParams) => Record<string, string | boolean>);
|
|
9
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Representation of an AdonisJS Vite Element returned
|
|
21
|
+
* by different tags generation APIs
|
|
22
|
+
*/
|
|
23
|
+
export type AdonisViteElement = {
|
|
24
|
+
tag: 'link';
|
|
25
|
+
attributes: Record<string, any>;
|
|
26
|
+
} | {
|
|
27
|
+
tag: 'script';
|
|
28
|
+
attributes: Record<string, any>;
|
|
29
|
+
children: string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Vite backend integration configuration options
|
|
33
|
+
*/
|
|
34
|
+
export type ViteOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Path to the hot file relative from the root of the
|
|
37
|
+
* application.
|
|
38
|
+
*
|
|
39
|
+
* @default public/assets/hot.json
|
|
40
|
+
*/
|
|
41
|
+
hotFile: string;
|
|
42
|
+
/**
|
|
43
|
+
* Public directory where the assets will be compiled.
|
|
44
|
+
*
|
|
45
|
+
* @default 'public/assets'
|
|
46
|
+
*/
|
|
47
|
+
buildDirectory: string;
|
|
48
|
+
/**
|
|
49
|
+
* The URL to prefix when generating assets URLs. For example: This
|
|
50
|
+
* could the CDN URL when generating the production build
|
|
51
|
+
*
|
|
52
|
+
* @default ''
|
|
53
|
+
*/
|
|
54
|
+
assetsUrl?: string;
|
|
55
|
+
/**
|
|
56
|
+
* A custom set of attributes to apply on all
|
|
57
|
+
* script tags
|
|
58
|
+
*/
|
|
59
|
+
scriptAttributes?: SetAttributes;
|
|
60
|
+
/**
|
|
61
|
+
* A custom set of attributes to apply on all
|
|
62
|
+
* style tags
|
|
63
|
+
*/
|
|
64
|
+
styleAttributes?: SetAttributes;
|
|
65
|
+
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array with unique items by the given key
|
|
3
|
+
*/
|
|
1
4
|
export declare function uniqBy<T>(array: T[], key: keyof T): T[];
|
|
2
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Convert Record of attributes to a valid HTML string
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeAttributes(attributes: Record<string, string | boolean>): string;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/vite
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Returns a new array with unique items by the given key
|
|
11
|
+
*/
|
|
1
12
|
export function uniqBy(array, key) {
|
|
2
13
|
const seen = new Set();
|
|
3
14
|
return array.filter((item) => {
|
|
@@ -5,3 +16,21 @@ export function uniqBy(array, key) {
|
|
|
5
16
|
return seen.has(k) ? false : seen.add(k);
|
|
6
17
|
});
|
|
7
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert Record of attributes to a valid HTML string
|
|
21
|
+
*/
|
|
22
|
+
export function makeAttributes(attributes) {
|
|
23
|
+
return Object.keys(attributes)
|
|
24
|
+
.map((key) => {
|
|
25
|
+
const value = attributes[key];
|
|
26
|
+
if (value === true) {
|
|
27
|
+
return key;
|
|
28
|
+
}
|
|
29
|
+
if (!value) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return `${key}="${value}"`;
|
|
33
|
+
})
|
|
34
|
+
.filter((attr) => attr !== null)
|
|
35
|
+
.join(' ');
|
|
36
|
+
}
|
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import type { Manifest } from 'vite';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { AdonisViteElement, ViteOptions } from './types/main.js';
|
|
3
|
+
/**
|
|
4
|
+
* Vite class exposes the APIs to generate tags and URLs for
|
|
5
|
+
* assets processed using vite.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Vite {
|
|
5
8
|
#private;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
constructor(options: ViteOptions);
|
|
10
|
+
/**
|
|
11
|
+
* Generate tags for the entry points
|
|
12
|
+
*/
|
|
13
|
+
generateEntryPointsTags(entryPoints: string[] | string, attributes?: Record<string, any>): AdonisViteElement[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns the dev server URL when running in hot
|
|
16
|
+
* mode. Otherwise an empty string
|
|
17
|
+
*/
|
|
18
|
+
devUrl(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the dev server URL when running in hot
|
|
21
|
+
* mode, otherwise returns the explicitly configured
|
|
22
|
+
* "assets" URL
|
|
23
|
+
*/
|
|
24
|
+
assetsUrl(): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns path to a given asset file
|
|
27
|
+
*/
|
|
9
28
|
assetPath(asset: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the manifest file contents
|
|
31
|
+
*
|
|
32
|
+
* @throws Will throw an exception when running in hot mode
|
|
33
|
+
*/
|
|
10
34
|
manifest(): Manifest;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
setAssetsUrl(url: string): this;
|
|
16
|
-
setScriptAttributes(attributes: SetAttributes): this;
|
|
17
|
-
setStyleAttributes(attributes: SetAttributes): this;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the script needed for the HMR working with React
|
|
37
|
+
*/
|
|
38
|
+
getReactHmrScript(attributes?: Record<string, any>): AdonisViteElement | null;
|
|
18
39
|
}
|
|
19
|
-
//# sourceMappingURL=vite.d.ts.map
|