@adonisjs/vite 0.0.1-6 → 0.0.1-7
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.js +6 -7
- package/build/providers/vite_provider.d.ts +1 -1
- package/build/providers/vite_provider.js +2 -0
- package/build/services/vite.d.ts +1 -1
- package/build/src/backend/define_config.js +1 -0
- package/build/src/backend/types/extended.d.ts +5 -0
- package/build/src/backend/utils.js +4 -2
- package/build/src/backend/vite.js +18 -14
- package/build/stubs/client_config.stub +1 -1
- package/build/stubs/js_entrypoint.stub +4 -0
- package/package.json +1 -1
package/build/configure.js
CHANGED
|
@@ -6,19 +6,18 @@
|
|
|
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
|
-
import { join } from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
9
|
/**
|
|
12
10
|
* Configures the package
|
|
13
11
|
*/
|
|
14
12
|
export async function configure(command) {
|
|
15
|
-
const stubDestination = join(fileURLToPath(command.app.appRoot), 'vite.config.js');
|
|
16
|
-
await command.publishStub('client_config.stub', {
|
|
17
|
-
destination: stubDestination,
|
|
18
|
-
});
|
|
19
13
|
await command.publishStub('config.stub');
|
|
14
|
+
await command.publishStub('client_config.stub');
|
|
15
|
+
await command.publishStub('js_entrypoint.stub');
|
|
20
16
|
await command.updateRcFile((rcFile) => {
|
|
21
17
|
rcFile.addProvider('@adonisjs/vite/vite_provider');
|
|
18
|
+
rcFile.addMetaFile('public/**', false);
|
|
22
19
|
});
|
|
23
|
-
await command.
|
|
20
|
+
if (await command.prompt.confirm('Do you want to install "vite"?')) {
|
|
21
|
+
await command.installPackages([{ name: 'vite', isDevDependency: true }]);
|
|
22
|
+
}
|
|
24
23
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
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
|
+
import debug from '../src/backend/debug.js';
|
|
9
10
|
export default class ViteServiceProvider {
|
|
10
11
|
app;
|
|
11
12
|
constructor(app) {
|
|
@@ -17,6 +18,7 @@ export default class ViteServiceProvider {
|
|
|
17
18
|
async getEdge() {
|
|
18
19
|
try {
|
|
19
20
|
const { default: edge } = await import('edge.js');
|
|
21
|
+
debug('Detected edge.js package. Adding Vite primitives to it');
|
|
20
22
|
return edge;
|
|
21
23
|
}
|
|
22
24
|
catch {
|
package/build/services/vite.d.ts
CHANGED
|
@@ -23,10 +23,12 @@ export function makeAttributes(attributes) {
|
|
|
23
23
|
return Object.keys(attributes)
|
|
24
24
|
.map((key) => {
|
|
25
25
|
const value = attributes[key];
|
|
26
|
-
if (value === true)
|
|
26
|
+
if (value === true) {
|
|
27
27
|
return key;
|
|
28
|
-
|
|
28
|
+
}
|
|
29
|
+
if (!value) {
|
|
29
30
|
return null;
|
|
31
|
+
}
|
|
30
32
|
return `${key}="${value}"`;
|
|
31
33
|
})
|
|
32
34
|
.filter((attr) => attr !== null)
|
|
@@ -70,30 +70,28 @@ export class Vite {
|
|
|
70
70
|
/**
|
|
71
71
|
* Create a script tag for the given path
|
|
72
72
|
*/
|
|
73
|
-
#makeScriptTag(src, url) {
|
|
73
|
+
#makeScriptTag(src, url, attributes) {
|
|
74
74
|
const customAttributes = this.#unwrapAttributes(src, url, this.#options.scriptAttributes);
|
|
75
|
-
const attributes = { type: 'module', ...customAttributes, src: url };
|
|
76
75
|
return this.#generateElement({
|
|
77
76
|
tag: 'script',
|
|
78
|
-
attributes,
|
|
77
|
+
attributes: { type: 'module', ...customAttributes, ...attributes, src: url },
|
|
79
78
|
children: [],
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
81
|
/**
|
|
83
82
|
* Create a style tag for the given path
|
|
84
83
|
*/
|
|
85
|
-
#makeStyleTag(src, url) {
|
|
84
|
+
#makeStyleTag(src, url, attributes) {
|
|
86
85
|
const customAttributes = this.#unwrapAttributes(src, url, this.#options.styleAttributes);
|
|
87
|
-
const attributes = { rel: 'stylesheet', ...customAttributes, href: url };
|
|
88
86
|
return this.#generateElement({
|
|
89
87
|
tag: 'link',
|
|
90
|
-
attributes,
|
|
88
|
+
attributes: { rel: 'stylesheet', ...customAttributes, ...attributes, href: url },
|
|
91
89
|
});
|
|
92
90
|
}
|
|
93
91
|
/**
|
|
94
92
|
* Generate a HTML tag for the given asset
|
|
95
93
|
*/
|
|
96
|
-
#generateTag(asset) {
|
|
94
|
+
#generateTag(asset, attributes) {
|
|
97
95
|
let url = '';
|
|
98
96
|
if (this.#isRunningHot()) {
|
|
99
97
|
url = this.#hotAsset(asset);
|
|
@@ -102,9 +100,9 @@ export class Vite {
|
|
|
102
100
|
url = `${this.#options.assetsUrl}/${asset}`;
|
|
103
101
|
}
|
|
104
102
|
if (this.#isCssPath(asset)) {
|
|
105
|
-
return this.#makeStyleTag(asset, url);
|
|
103
|
+
return this.#makeStyleTag(asset, url, attributes);
|
|
106
104
|
}
|
|
107
|
-
return this.#makeScriptTag(asset, url);
|
|
105
|
+
return this.#makeScriptTag(asset, url, attributes);
|
|
108
106
|
}
|
|
109
107
|
/**
|
|
110
108
|
* Generates a JSON element with a custom toString implementation
|
|
@@ -138,24 +136,30 @@ export class Vite {
|
|
|
138
136
|
* Generate style and script tags for the given entrypoints
|
|
139
137
|
* Also adds the @vite/client script
|
|
140
138
|
*/
|
|
141
|
-
#generateEntryPointsTagsForHotMode(entryPoints) {
|
|
139
|
+
#generateEntryPointsTagsForHotMode(entryPoints, attributes) {
|
|
142
140
|
const viteHmr = this.#getViteHmrScript();
|
|
143
|
-
const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint));
|
|
141
|
+
const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint, attributes));
|
|
144
142
|
return viteHmr ? [viteHmr].concat(tags) : tags;
|
|
145
143
|
}
|
|
146
144
|
/**
|
|
147
145
|
* Generate style and script tags for the given entrypoints
|
|
148
146
|
* using the manifest file
|
|
149
147
|
*/
|
|
150
|
-
#generateEntryPointsTagsWithManifest(entryPoints) {
|
|
148
|
+
#generateEntryPointsTagsWithManifest(entryPoints, attributes) {
|
|
151
149
|
const manifest = this.manifest();
|
|
152
150
|
const tags = [];
|
|
153
151
|
for (const entryPoint of entryPoints) {
|
|
154
152
|
const chunk = this.#chunk(manifest, entryPoint);
|
|
155
|
-
tags.push({
|
|
153
|
+
tags.push({
|
|
154
|
+
path: chunk.file,
|
|
155
|
+
tag: this.#generateTag(chunk.file, { ...attributes, integrity: chunk.integrity }),
|
|
156
|
+
});
|
|
156
157
|
for (const css of chunk.css || []) {
|
|
157
158
|
const cssChunk = this.#chunkByFile(manifest, css);
|
|
158
|
-
tags.push({
|
|
159
|
+
tags.push({
|
|
160
|
+
path: cssChunk.file,
|
|
161
|
+
tag: this.#generateTag(cssChunk.file, { ...attributes, integrity: cssChunk.integrity }),
|
|
162
|
+
});
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
return uniqBy(tags, 'path')
|