@despia/local 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/src/vite.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Vite plugin for generating despia/local.json manifest
3
+ */
4
+
5
+ import { resolve } from 'path';
6
+ import { generateManifest } from './core.js';
7
+
8
+ /**
9
+ * Vite plugin to generate despia/local.json manifest
10
+ * @param {Object} options
11
+ * @param {string} options.outDir - Output directory (default: 'dist')
12
+ * @param {string} options.entryHtml - Entry HTML file (default: 'index.html')
13
+ */
14
+ export function despiaOfflinePlugin(options = {}) {
15
+ const { outDir = 'dist', entryHtml = 'index.html' } = options;
16
+
17
+ return {
18
+ name: 'despia-offline',
19
+ apply: 'build',
20
+ writeBundle(bundleOptions, bundle) {
21
+ const outputDir = bundleOptions.dir || outDir;
22
+ const additionalPaths = [];
23
+
24
+ // Collect paths from bundle
25
+ for (const [fileName, chunk] of Object.entries(bundle)) {
26
+ if (chunk.type === 'asset' || chunk.type === 'chunk') {
27
+ const filePath = chunk.fileName || fileName;
28
+ const rootRelativePath = filePath.startsWith('/')
29
+ ? filePath
30
+ : '/' + filePath.replace(/\\/g, '/');
31
+ additionalPaths.push(rootRelativePath);
32
+ }
33
+ }
34
+
35
+ try {
36
+ const paths = generateManifest({
37
+ outputDir,
38
+ entryHtml,
39
+ additionalPaths
40
+ });
41
+ console.log(`✓ Generated despia/local.json with ${paths.length} assets`);
42
+ } catch (error) {
43
+ console.error('Error generating despia/local.json:', error.message);
44
+ }
45
+ }
46
+ };
47
+ }
package/src/webpack.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Webpack plugin for generating despia/local.json manifest
3
+ */
4
+
5
+ import { generateManifest } from './core.js';
6
+
7
+ class DespiaOfflinePlugin {
8
+ constructor(options = {}) {
9
+ this.options = {
10
+ outDir: options.outDir || 'dist',
11
+ entryHtml: options.entryHtml || 'index.html',
12
+ ...options
13
+ };
14
+ }
15
+
16
+ apply(compiler) {
17
+ const pluginName = 'DespiaOfflinePlugin';
18
+
19
+ compiler.hooks.afterEmit.tapAsync(pluginName, (compilation, callback) => {
20
+ // Get output path from webpack compiler
21
+ const outputPath = compilation.compiler.outputPath || this.options.outDir;
22
+ const additionalPaths = [];
23
+
24
+ // Collect all emitted assets
25
+ for (const [filename, asset] of Object.entries(compilation.assets)) {
26
+ if (asset) {
27
+ const rootRelativePath = '/' + filename.replace(/\\/g, '/');
28
+ additionalPaths.push(rootRelativePath);
29
+ }
30
+ }
31
+
32
+ // Also collect from compilation.getAssets() if available (webpack 5)
33
+ if (compilation.getAssets) {
34
+ for (const asset of compilation.getAssets()) {
35
+ const rootRelativePath = '/' + asset.name.replace(/\\/g, '/');
36
+ additionalPaths.push(rootRelativePath);
37
+ }
38
+ }
39
+
40
+ try {
41
+ const paths = generateManifest({
42
+ outputDir: outputPath,
43
+ entryHtml: this.options.entryHtml,
44
+ additionalPaths
45
+ });
46
+ console.log(`✓ Generated despia/local.json with ${paths.length} assets`);
47
+ } catch (error) {
48
+ console.error('Error generating despia/local.json:', error.message);
49
+ }
50
+
51
+ callback();
52
+ });
53
+ }
54
+ }
55
+
56
+ export default DespiaOfflinePlugin;