@adonisjs/vite 0.0.1-2 → 0.0.1-4

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.
Files changed (65) hide show
  1. package/build/configure.d.ts +3 -1
  2. package/build/configure.js +12 -1
  3. package/build/index.d.ts +0 -1
  4. package/build/index.js +8 -0
  5. package/build/providers/vite_provider.d.ts +4 -3
  6. package/build/providers/vite_provider.js +31 -8
  7. package/build/services/vite.d.ts +0 -1
  8. package/build/services/vite.js +12 -0
  9. package/build/src/backend/types/extended.d.ts +3 -1
  10. package/build/src/backend/types/extended.js +8 -0
  11. package/build/src/backend/types/main.d.ts +10 -1
  12. package/build/src/backend/types/main.js +8 -0
  13. package/build/src/backend/utils.d.ts +3 -1
  14. package/build/src/backend/utils.js +11 -0
  15. package/build/src/backend/vite.d.ts +42 -1
  16. package/build/src/backend/vite.js +137 -7
  17. package/build/src/vite_plugin/config.d.ts +6 -1
  18. package/build/src/vite_plugin/config.js +26 -0
  19. package/build/src/vite_plugin/config_resolver.d.ts +12 -1
  20. package/build/src/vite_plugin/config_resolver.js +20 -0
  21. package/build/src/vite_plugin/helpers/inertia.d.ts +3 -1
  22. package/build/src/vite_plugin/helpers/inertia.js +11 -0
  23. package/build/src/vite_plugin/hot_file.d.ts +6 -1
  24. package/build/src/vite_plugin/hot_file.js +20 -0
  25. package/build/src/vite_plugin/index.d.ts +3 -1
  26. package/build/src/vite_plugin/index.js +11 -0
  27. package/build/src/vite_plugin/types/index.d.ts +32 -1
  28. package/build/src/vite_plugin/types/index.js +8 -0
  29. package/build/src/vite_plugin/utils.d.ts +6 -1
  30. package/build/src/vite_plugin/utils.js +14 -0
  31. package/build/stubs/index.d.ts +0 -1
  32. package/build/stubs/index.js +2 -2
  33. package/build/stubs/vite/vite_config.stub +8 -4
  34. package/package.json +56 -90
  35. package/build/configure.d.ts.map +0 -1
  36. package/build/index.d.ts.map +0 -1
  37. package/build/providers/vite_provider.d.ts.map +0 -1
  38. package/build/services/vite.d.ts.map +0 -1
  39. package/build/src/backend/types/extended.d.ts.map +0 -1
  40. package/build/src/backend/types/main.d.ts.map +0 -1
  41. package/build/src/backend/utils.d.ts.map +0 -1
  42. package/build/src/backend/vite.d.ts.map +0 -1
  43. package/build/src/vite_plugin/config.d.ts.map +0 -1
  44. package/build/src/vite_plugin/config_resolver.d.ts.map +0 -1
  45. package/build/src/vite_plugin/helpers/inertia.d.ts.map +0 -1
  46. package/build/src/vite_plugin/hot_file.d.ts.map +0 -1
  47. package/build/src/vite_plugin/index.d.ts.map +0 -1
  48. package/build/src/vite_plugin/types/index.d.ts.map +0 -1
  49. package/build/src/vite_plugin/utils.d.ts.map +0 -1
  50. package/build/stubs/index.d.ts.map +0 -1
  51. package/configure.ts +0 -30
  52. package/index.ts +0 -15
  53. package/providers/vite_provider.ts +0 -89
  54. package/services/vite.ts +0 -23
  55. package/src/backend/types/extended.ts +0 -19
  56. package/src/backend/types/main.ts +0 -31
  57. package/src/backend/utils.ts +0 -19
  58. package/src/backend/vite.ts +0 -367
  59. package/src/vite_plugin/config.ts +0 -97
  60. package/src/vite_plugin/config_resolver.ts +0 -62
  61. package/src/vite_plugin/helpers/inertia.ts +0 -27
  62. package/src/vite_plugin/hot_file.ts +0 -58
  63. package/src/vite_plugin/index.ts +0 -38
  64. package/src/vite_plugin/types/index.ts +0 -56
  65. package/src/vite_plugin/utils.ts +0 -40
@@ -1,3 +1,5 @@
1
1
  import type Configure from '@adonisjs/core/commands/configure';
2
+ /**
3
+ * Configures the package
4
+ */
2
5
  export declare function configure(command: Configure): Promise<void>;
3
- //# sourceMappingURL=configure.d.ts.map
@@ -1,12 +1,23 @@
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 { join } from 'node:path';
2
10
  import { fileURLToPath } from 'node:url';
11
+ /**
12
+ * Configures the package
13
+ */
3
14
  export async function configure(command) {
4
15
  const stubDestination = join(fileURLToPath(command.app.appRoot), 'vite.config.js');
5
16
  await command.publishStub('vite/vite_config.stub', {
6
17
  destination: stubDestination,
7
18
  });
8
19
  await command.updateRcFile((rcFile) => {
9
- rcFile.addProvider('@adonisjs/vite/providers/vite_provider');
20
+ rcFile.addProvider('@adonisjs/vite/vite_provider');
10
21
  });
11
22
  const packagesToInstall = [{ name: 'vite', isDevDependency: true }];
12
23
  command.listPackagesToInstall(packagesToInstall);
package/build/index.d.ts CHANGED
@@ -2,4 +2,3 @@ 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
- //# sourceMappingURL=index.d.ts.map
package/build/index.js CHANGED
@@ -1,3 +1,11 @@
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';
@@ -1,10 +1,11 @@
1
- import '@adonisjs/view';
2
- import { ApplicationService } from '@adonisjs/core/types';
1
+ import type { ApplicationService } from '@adonisjs/core/types';
3
2
  export default class ViteServiceProvider {
4
3
  #private;
5
4
  protected app: ApplicationService;
6
5
  constructor(app: ApplicationService);
7
6
  register(): void;
7
+ /**
8
+ * Extend the view globals with vite tags and globals
9
+ */
8
10
  boot(): Promise<void>;
9
11
  }
10
- //# sourceMappingURL=vite_provider.d.ts.map
@@ -1,17 +1,29 @@
1
- import '@adonisjs/view';
2
- import { Vite } from '../src/backend/vite.js';
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
+ */
3
9
  import { EdgeError } from 'edge-error';
4
10
  export default class ViteServiceProvider {
5
11
  app;
6
12
  constructor(app) {
7
13
  this.app = app;
8
14
  }
15
+ /**
16
+ * Inject the script needed for Vite HMR
17
+ */
9
18
  #registerViteTag(view) {
10
19
  view.registerTag({
11
20
  tagName: 'vite',
12
21
  seekable: true,
13
22
  block: false,
14
23
  compile(parser, buffer, token) {
24
+ /**
25
+ * Ensure an argument is defined
26
+ */
15
27
  if (!token.properties.jsArg.trim()) {
16
28
  throw new EdgeError('Missing entrypoint name', 'E_RUNTIME_EXCEPTION', {
17
29
  filename: token.filename,
@@ -25,6 +37,9 @@ export default class ViteServiceProvider {
25
37
  },
26
38
  });
27
39
  }
40
+ /**
41
+ * Inject a script needed for the HMR working with React
42
+ */
28
43
  #registerViteReactTag(view) {
29
44
  view.registerTag({
30
45
  tagName: 'viteReactRefresh',
@@ -36,13 +51,21 @@ export default class ViteServiceProvider {
36
51
  });
37
52
  }
38
53
  register() {
39
- this.app.container.singleton('vite', async () => new Vite(this.app));
54
+ this.app.container.singleton('vite', async () => {
55
+ const { Vite } = await import('../src/backend/vite.js');
56
+ return new Vite(this.app);
57
+ });
40
58
  }
59
+ /**
60
+ * Extend the view globals with vite tags and globals
61
+ */
41
62
  async boot() {
42
- const view = await this.app.container.make('view');
43
- const vite = await this.app.container.make('vite');
44
- view.global('vite', vite);
45
- this.#registerViteTag(view);
46
- this.#registerViteReactTag(view);
63
+ this.app.container.resolving('view', async (view) => {
64
+ const vite = await this.app.container.make('vite');
65
+ view.global('vite', vite);
66
+ view.global('asset', vite.assetPath.bind(vite));
67
+ this.#registerViteTag(view);
68
+ this.#registerViteReactTag(view);
69
+ });
47
70
  }
48
71
  }
@@ -1,4 +1,3 @@
1
1
  import { Vite } from '../index.js';
2
2
  declare let vite: Vite;
3
3
  export { vite as default };
4
- //# sourceMappingURL=vite.d.ts.map
@@ -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
  });
@@ -1,7 +1,9 @@
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
- //# sourceMappingURL=extended.d.ts.map
@@ -1 +1,9 @@
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
  export {};
@@ -1,9 +1,18 @@
1
+ /**
2
+ * Content 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
- //# sourceMappingURL=main.d.ts.map
@@ -1 +1,9 @@
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
  export {};
@@ -1,2 +1,4 @@
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
- //# sourceMappingURL=utils.d.ts.map
@@ -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,15 +5,56 @@ export declare class Vite {
5
5
  #private;
6
6
  private application;
7
7
  constructor(application: ApplicationService);
8
+ /**
9
+ * Generate tags for the entry points
10
+ */
8
11
  generateEntryPointsTags(entryPoints: string[] | string): string;
12
+ /**
13
+ * Returns path to a given asset file
14
+ */
9
15
  assetPath(asset: string): string;
16
+ /**
17
+ * Returns the manifest file content
18
+ *
19
+ * @throws Will throw an exception when running in hot mode
20
+ */
10
21
  manifest(): Manifest;
22
+ /**
23
+ * Returns the script needed for the HMR working with React
24
+ *
25
+ * This method is called automatically when using edge tag `@viteReactRefresh`
26
+ */
11
27
  getReactHmrScript(): string;
28
+ /**
29
+ * Set the path to the hotfile
30
+ *
31
+ * You must also set the `hotFile` option in the vite plugin config
32
+ */
12
33
  setHotFilePath(path: string): this;
34
+ /**
35
+ * Set the manifest filename
36
+ *
37
+ * You must also set the `build.manifest` option in your vite configuration
38
+ */
13
39
  setManifestFilename(name: string): this;
40
+ /**
41
+ * Set the build directory. Subdirectory of the AdonisJs public directory
42
+ *
43
+ * You must also set the `buildDirectory` option in the vite plugin config
44
+ */
14
45
  setBuildDirectory(path: string): this;
46
+ /**
47
+ * Set the assets url
48
+ *
49
+ * You must also set the `assetsUrl` option in the vite plugin config
50
+ */
15
51
  setAssetsUrl(url: string): this;
52
+ /**
53
+ * Include additional attributes to each script tag generated
54
+ */
16
55
  setScriptAttributes(attributes: SetAttributes): this;
56
+ /**
57
+ * Include additional attributes to each style tag generated
58
+ */
17
59
  setStyleAttributes(attributes: SetAttributes): this;
18
60
  }
19
- //# sourceMappingURL=vite.d.ts.map
@@ -1,44 +1,101 @@
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 { join } from 'node:path';
2
10
  import { fileURLToPath } from 'node:url';
3
11
  import { existsSync, readFileSync } from 'node:fs';
4
12
  import { uniqBy } from './utils.js';
5
13
  export class Vite {
6
14
  application;
15
+ /**
16
+ * Path to the build directory
17
+ *
18
+ * @default 'public/assets'
19
+ */
7
20
  #buildDirectory;
21
+ /**
22
+ * Path to the hotfile
23
+ *
24
+ * @default 'public/assets/hot.json'
25
+ */
8
26
  #hotFile;
27
+ /**
28
+ * Manifest file name
29
+ */
9
30
  #manifestFilename = 'manifest.json';
31
+ /**
32
+ * Assets URL
33
+ */
10
34
  #assetsUrl = '';
35
+ /**
36
+ * We cache the manifest file content in production
37
+ * to avoid reading the file multiple times
38
+ */
11
39
  #manifestCache = null;
40
+ /**
41
+ * Attributes to be set on the style tags
42
+ */
12
43
  #styleAttributes = {};
44
+ /**
45
+ * Attributes to be set on the script tags
46
+ */
13
47
  #scriptAttributes = {};
14
48
  constructor(application) {
15
49
  this.application = application;
16
50
  this.#buildDirectory = this.application.publicPath('assets');
17
51
  this.#hotFile = join(this.#buildDirectory, 'hot.json');
18
52
  }
53
+ /**
54
+ * Checks if the application is running in hot mode
55
+ */
19
56
  #isRunningHot() {
20
57
  return existsSync(this.#hotFile);
21
58
  }
59
+ /**
60
+ * Reads the file contents as JSON
61
+ */
22
62
  #readFileAsJSON(filePath) {
23
63
  return JSON.parse(readFileSync(filePath, 'utf-8'));
24
64
  }
65
+ /**
66
+ * Returns the parsed hot file content
67
+ */
25
68
  #readHotFile() {
26
69
  return this.#readFileAsJSON(this.#hotFile);
27
70
  }
71
+ /**
72
+ * Get the path to an asset when running in hot mode
73
+ */
28
74
  #hotAsset(asset) {
29
75
  return this.#readHotFile().url + '/' + asset;
30
76
  }
77
+ /**
78
+ * Returns the script needed for the HMR working with Vite
79
+ */
31
80
  #getViteHmrScript() {
32
81
  if (!this.#isRunningHot()) {
33
82
  return '';
34
83
  }
35
84
  return `<script type="module" src="${this.#hotAsset('@vite/client')}"></script>`;
36
85
  }
86
+ /**
87
+ * Generate style and script tags for the given entrypoints
88
+ * Also add the @vite/client script
89
+ */
37
90
  #generateEntryPointsTagsForHotmode(entryPoints) {
38
91
  const viteHmr = this.#getViteHmrScript();
39
92
  const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint));
40
93
  return [viteHmr, ...tags].join('\n');
41
94
  }
95
+ /**
96
+ * Generate style and script tags for the given entrypoints
97
+ * using the manifest file
98
+ */
42
99
  #generateEntryPointsTagsWithManifest(entryPoints) {
43
100
  const manifest = this.manifest();
44
101
  const tags = [];
@@ -55,13 +112,9 @@ export class Vite {
55
112
  .map((preload) => preload.tag)
56
113
  .join('\n');
57
114
  }
58
- generateEntryPointsTags(entryPoints) {
59
- entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints];
60
- if (this.#isRunningHot()) {
61
- return this.#generateEntryPointsTagsForHotmode(entryPoints);
62
- }
63
- return this.#generateEntryPointsTagsWithManifest(entryPoints);
64
- }
115
+ /**
116
+ * Get a chunk from the manifest file for a given file name
117
+ */
65
118
  #chunk(manifest, fileName) {
66
119
  const chunk = manifest[fileName];
67
120
  if (!chunk) {
@@ -69,6 +122,9 @@ export class Vite {
69
122
  }
70
123
  return chunk;
71
124
  }
125
+ /**
126
+ * Get a chunk from the manifest file for a given hashed file name
127
+ */
72
128
  #chunkByFile(manifest, fileName) {
73
129
  const chunk = Object.values(manifest).find((c) => c.file === fileName);
74
130
  if (!chunk) {
@@ -76,9 +132,15 @@ export class Vite {
76
132
  }
77
133
  return chunk;
78
134
  }
135
+ /**
136
+ * Check if the given path is a CSS path
137
+ */
79
138
  #isCssPath(path) {
80
139
  return path.match(/\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/) !== null;
81
140
  }
141
+ /**
142
+ * Generate a HTML tag for the given asset
143
+ */
82
144
  #generateTag(asset) {
83
145
  let url = '';
84
146
  if (this.#isRunningHot()) {
@@ -92,12 +154,19 @@ export class Vite {
92
154
  }
93
155
  return this.#makeScriptTag(asset, url);
94
156
  }
157
+ /**
158
+ * Unwrap attributes from the user defined function or return
159
+ * the attributes as it is
160
+ */
95
161
  #unwrapAttributes(src, url, attributes) {
96
162
  if (typeof attributes === 'function') {
97
163
  return attributes({ src, url });
98
164
  }
99
165
  return attributes;
100
166
  }
167
+ /**
168
+ * Convert Record of attributes to a valid HTML string
169
+ */
101
170
  #makeAttributes(attributes) {
102
171
  return Object.keys(attributes)
103
172
  .map((key) => {
@@ -111,16 +180,35 @@ export class Vite {
111
180
  .filter((attr) => attr !== null)
112
181
  .join(' ');
113
182
  }
183
+ /**
184
+ * Create a script tag for the given path
185
+ */
114
186
  #makeScriptTag(src, url) {
115
187
  const customAttributes = this.#unwrapAttributes(src, url, this.#scriptAttributes);
116
188
  const attributes = { type: 'module', ...customAttributes };
117
189
  return `<script ${this.#makeAttributes(attributes)} src="${url}"></script>`;
118
190
  }
191
+ /**
192
+ * Create a style tag for the given path
193
+ */
119
194
  #makeStyleTag(src, url) {
120
195
  const customAttributes = this.#unwrapAttributes(src, url, this.#styleAttributes);
121
196
  const attributes = { rel: 'stylesheet', ...customAttributes };
122
197
  return `<link ${this.#makeAttributes(attributes)} href="${url}">`;
123
198
  }
199
+ /**
200
+ * Generate tags for the entry points
201
+ */
202
+ generateEntryPointsTags(entryPoints) {
203
+ entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints];
204
+ if (this.#isRunningHot()) {
205
+ return this.#generateEntryPointsTagsForHotmode(entryPoints);
206
+ }
207
+ return this.#generateEntryPointsTagsWithManifest(entryPoints);
208
+ }
209
+ /**
210
+ * Returns path to a given asset file
211
+ */
124
212
  assetPath(asset) {
125
213
  if (this.#isRunningHot()) {
126
214
  return this.#hotAsset(asset);
@@ -128,19 +216,35 @@ export class Vite {
128
216
  const chunk = this.#chunk(this.manifest(), asset);
129
217
  return `${this.#assetsUrl}/assets/${chunk.file}`;
130
218
  }
219
+ /**
220
+ * Returns the manifest file content
221
+ *
222
+ * @throws Will throw an exception when running in hot mode
223
+ */
131
224
  manifest() {
132
225
  if (this.#isRunningHot()) {
133
226
  throw new Error('Cannot read the manifest file when running in hot mode');
134
227
  }
228
+ /**
229
+ * Use in-memory cache when available
230
+ */
135
231
  if (this.#manifestCache) {
136
232
  return this.#manifestCache;
137
233
  }
138
234
  const manifest = this.#readFileAsJSON(join(this.#buildDirectory, this.#manifestFilename));
235
+ /**
236
+ * Cache the manifest in production to avoid re-reading the file from disk
237
+ */
139
238
  if (this.application.inProduction) {
140
239
  this.#manifestCache = manifest;
141
240
  }
142
241
  return manifest;
143
242
  }
243
+ /**
244
+ * Returns the script needed for the HMR working with React
245
+ *
246
+ * This method is called automatically when using edge tag `@viteReactRefresh`
247
+ */
144
248
  getReactHmrScript() {
145
249
  if (!this.#isRunningHot()) {
146
250
  return '';
@@ -155,26 +259,52 @@ export class Vite {
155
259
  </script>
156
260
  `;
157
261
  }
262
+ /**
263
+ * Set the path to the hotfile
264
+ *
265
+ * You must also set the `hotFile` option in the vite plugin config
266
+ */
158
267
  setHotFilePath(path) {
159
268
  this.#hotFile = join(fileURLToPath(this.application.appRoot), path);
160
269
  return this;
161
270
  }
271
+ /**
272
+ * Set the manifest filename
273
+ *
274
+ * You must also set the `build.manifest` option in your vite configuration
275
+ */
162
276
  setManifestFilename(name) {
163
277
  this.#manifestFilename = name;
164
278
  return this;
165
279
  }
280
+ /**
281
+ * Set the build directory. Subdirectory of the AdonisJs public directory
282
+ *
283
+ * You must also set the `buildDirectory` option in the vite plugin config
284
+ */
166
285
  setBuildDirectory(path) {
167
286
  this.#buildDirectory = this.application.publicPath(path);
168
287
  return this;
169
288
  }
289
+ /**
290
+ * Set the assets url
291
+ *
292
+ * You must also set the `assetsUrl` option in the vite plugin config
293
+ */
170
294
  setAssetsUrl(url) {
171
295
  this.#assetsUrl = url.endsWith('/') ? url : `${url}/`;
172
296
  return this;
173
297
  }
298
+ /**
299
+ * Include additional attributes to each script tag generated
300
+ */
174
301
  setScriptAttributes(attributes) {
175
302
  this.#scriptAttributes = attributes;
176
303
  return this;
177
304
  }
305
+ /**
306
+ * Include additional attributes to each style tag generated
307
+ */
178
308
  setStyleAttributes(attributes) {
179
309
  this.#styleAttributes = attributes;
180
310
  return this;
@@ -1,5 +1,10 @@
1
1
  import { ConfigEnv, Plugin, UserConfig } from 'vite';
2
2
  import { PluginFullOptions } from './types/index.js';
3
+ /**
4
+ * Vite config hook
5
+ */
3
6
  export declare const configHook: (options: PluginFullOptions, userConfig: UserConfig, { command }: ConfigEnv) => UserConfig;
7
+ /**
8
+ * Update the user vite config to match the Adonis requirements
9
+ */
4
10
  export declare const config: (options: PluginFullOptions) => Plugin;
5
- //# sourceMappingURL=config.d.ts.map
@@ -1,14 +1,29 @@
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 { defu } from 'defu';
2
10
  import { resolveDevServerUrl } from './utils.js';
3
11
  import { HotFile } from './hot_file.js';
4
12
  import { ConfigResolver } from './config_resolver.js';
5
13
  import { join } from 'node:path';
14
+ /**
15
+ * Vite config hook
16
+ */
6
17
  export const configHook = (options, userConfig, { command }) => {
7
18
  const config = {
8
19
  publicDir: userConfig.publicDir ?? false,
9
20
  base: ConfigResolver.resolveBase(userConfig, options, command),
10
21
  resolve: { alias: ConfigResolver.resolveAlias(userConfig) },
11
22
  server: {
23
+ /**
24
+ * Will allow to rewrite the URL to the public path
25
+ * in dev mode
26
+ */
12
27
  origin: '__adonis_vite__',
13
28
  },
14
29
  build: {
@@ -23,11 +38,17 @@ export const configHook = (options, userConfig, { command }) => {
23
38
  };
24
39
  return defu(config, userConfig);
25
40
  };
41
+ /**
42
+ * Update the user vite config to match the Adonis requirements
43
+ */
26
44
  export const config = (options) => {
27
45
  let devServerUrl;
28
46
  return {
29
47
  name: 'vite-plugin-adonis:config',
30
48
  config: configHook.bind(null, options),
49
+ /**
50
+ * Store the dev server url for further usage when rewriting URLs
51
+ */
31
52
  configureServer(server) {
32
53
  const hotfile = new HotFile(options.hotFile);
33
54
  server.httpServer?.once('listening', async () => {
@@ -36,6 +57,11 @@ export const config = (options) => {
36
57
  });
37
58
  server.httpServer?.on('close', () => hotfile.clean());
38
59
  },
60
+ /**
61
+ * Rewrite URL to the public path in dev mode
62
+ *
63
+ * See : https://nystudio107.com/blog/using-vite-js-next-generation-frontend-tooling-with-craft-cms#vite-processed-assets
64
+ */
39
65
  transform: (code) => ({
40
66
  code: code.replace(/__adonis_vite__/g, devServerUrl),
41
67
  map: null,
@@ -2,8 +2,19 @@ import { ResolvedConfig, UserConfig, AliasOptions } from 'vite';
2
2
  import { PluginFullOptions } from './types/index.js';
3
3
  export declare class ConfigResolver {
4
4
  static resolvedConfig?: ResolvedConfig;
5
+ /**
6
+ * Resolve the `config.base` value
7
+ */
5
8
  static resolveBase(config: UserConfig, options: PluginFullOptions, command: 'build' | 'serve'): string;
9
+ /**
10
+ * Resolve the `config.resolve.alias` value
11
+ *
12
+ * Basically we are merging the user defined alias with the
13
+ * default alias.
14
+ */
6
15
  static resolveAlias(config: UserConfig): AliasOptions;
16
+ /**
17
+ * Resolve the `config.build.outDir` value
18
+ */
7
19
  static resolveOutDir(config: UserConfig, options: PluginFullOptions): string;
8
20
  }
9
- //# sourceMappingURL=config_resolver.d.ts.map