@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.
@@ -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.installPackages([{ name: 'vite', isDevDependency: true }]);
20
+ if (await command.prompt.confirm('Do you want to install "vite"?')) {
21
+ await command.installPackages([{ name: 'vite', isDevDependency: true }]);
22
+ }
24
23
  }
@@ -1,5 +1,5 @@
1
+ import type { Edge } from 'edge.js';
1
2
  import type { ApplicationService } from '@adonisjs/core/types';
2
- import { Edge } from 'edge.js';
3
3
  export default class ViteServiceProvider {
4
4
  protected app: ApplicationService;
5
5
  constructor(app: ApplicationService);
@@ -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 {
@@ -1,3 +1,3 @@
1
- import { Vite } from '../index.js';
1
+ import type { Vite } from '../src/backend/vite.js';
2
2
  declare let vite: Vite;
3
3
  export { vite as default };
@@ -13,6 +13,7 @@ export function defineConfig(config) {
13
13
  return {
14
14
  buildDirectory: 'public/assets',
15
15
  hotFile: 'public/assets/hot.json',
16
+ assetsUrl: '/assets',
16
17
  ...config,
17
18
  };
18
19
  }
@@ -7,3 +7,8 @@ declare module '@adonisjs/core/types' {
7
7
  vite: Vite;
8
8
  }
9
9
  }
10
+ declare module 'vite' {
11
+ interface ManifestChunk {
12
+ integrity: string;
13
+ }
14
+ }
@@ -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
- if (value === false)
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({ path: chunk.file, tag: this.#generateTag(chunk.file) });
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({ path: cssChunk.file, tag: this.#generateTag(cssChunk.file) });
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')
@@ -1,5 +1,5 @@
1
1
  ---
2
- to: {{ destination }}
2
+ to: {{ app.makePath('vite.config.js') }}
3
3
  ---
4
4
  import { defineConfig } from 'vite'
5
5
  import adonisjs from '@adonisjs/vite/client'
@@ -0,0 +1,4 @@
1
+ ---
2
+ to: {{ app.makePath('resources/js/app.js') }}
3
+ ---
4
+ console.log('Log from JS entrypoint')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/vite",
3
3
  "description": "Vite plugin for Adonis.js",
4
- "version": "0.0.1-6",
4
+ "version": "0.0.1-7",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },