MacFJA / svelte-adapter-neutralino

A SvelteKit adapter to generate a Neutralinojs application
MIT License
16 stars 2 forks source link

Does this modify the behavior of static adapter or the passed object? #4

Open aleritty opened 1 year ago

aleritty commented 1 year ago

I have a simple sveltekit project where I need to link to resources not handled by sveltekit. Therefore I needed to pass "strict: false" to svelte static adapter. I also wanted to use a second adapter to crate a neutralino's app.

It works when I do it directly, like this:

import staticAdapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: staticAdapter({
            strict: false,
            pages: 'build/static',
            assets: 'build/static',
            fallback: 'index.html',
            precompress: false
        })
    }
};

export default config;

But it doesn't when I use it inside the multi adapter with neutralino-adapter, like this:

import staticAdapter from '@sveltejs/adapter-static';
import neutralinoAdapter from '@macfja/svelte-adapter-neutralino';
import multiAdapter from '@macfja/svelte-multi-adapter';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: multiAdapter([
            staticAdapter({
                strict: false,
                pages: 'build/static',
                assets: 'build/static',
                fallback: 'index.html',
                precompress: false,
                handleHttpError: 'ignore'
            }),
            neutralinoAdapter({
                name: 'APP',
                icon: 'static/favicon.png',
                applicationId: 'de.APP.com',
                output: 'build/neutralino',
                window: {
                    width: 1024,
                    height: 768,
                    minWidth: 400,
                    minHeight: 200,
                    resizable: true,
                    maximize: true
                }
            })
        ])
    }
};
export default config;

Error message:

 @sveltejs/adapter-static: all routes must be fully prerenderable, but found the following routes that are dynamic:
[...]
  You have the following options:
    - set the `fallback` option — see https://kit.svelte.dev/docs/single-page-apps#usage for more info.
    - add `export const prerender = true` to your root `+layout.js/.ts` or `+layout.server.js/.ts` file. This will try to prerender all pages.
    - add `export const prerender = true` to any `+server.js/ts` files that are not fetched by page `load` functions.
    - pass `strict: false` to `adapter-static` to ignore this error. Only do this if you are sure you don't need the routes in question in your final app, as they will be unavailable. See https://github.com/sveltejs/kit/tree/master/packages/adapter-static#strict for more info.

These are my package.json dependencies:

    "devDependencies": {
        "@aleritty/svelte-adapter-neutralino": "git+https://github.com/aleritty/svelte-adapter-neutralino.git",
        "@fortawesome/svelte-fontawesome": "^0.2.0",
        "@macfja/svelte-multi-adapter": "^1.0.2",
        "@sveltejs/adapter-static": "^2.0.2",
        "@sveltejs/kit": "^1.20.2",
        "@typescript-eslint/eslint-plugin": "^5.59.11",
        "@typescript-eslint/parser": "^5.59.11",
        "autoprefixer": "^10.4.14",
        "daisyui": "^3.1.0",
        "eslint": "^8.42.0",
        "eslint-config-prettier": "^8.8.0",
        "eslint-plugin-svelte": "^2.30.0",
        "eslint-plugin-svelte3": "^4.0.0",
        "postcss-load-config": "^4.0.1",
        "prettier": "^2.8.8",
        "prettier-plugin-svelte": "^2.10.1",
        "sass": "^1.63.4",
        "svelte": "^3.59.1",
        "svelte-check": "^3.4.3",
        "svelte-i18n": "^3.6.0",
        "svelte-notifications": "^0.9.98",
        "svelte-preprocess": "^5.0.4",
        "tailwindcss": "^3.3.2",
        "tslib": "^2.5.3",
        "typescript": "^5.1.3",
        "vite": "^4.3.9"
    },

I'm not sure what can be the cause.

aleritty commented 1 year ago

But it work when just commenting out the neutralino-adapter.


import staticAdapter from '@sveltejs/adapter-static';
import neutralinoAdapter from '@macfja/svelte-adapter-neutralino';
import multiAdapter from '@macfja/svelte-multi-adapter';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: multiAdapter([
            staticAdapter({
                strict: false,
                pages: 'build/static',
                assets: 'build/static',
                fallback: 'index.html',
                precompress: false,
                handleHttpError: 'ignore'
        // }),
        // neutralinoAdapter({
        //  name: 'ALS-Stift',
        //  icon: 'static/favicon.png',
        //  applicationId: 'de.apstresearch.als-stift',
        //  output: 'build/neutralino',
        //  window: {
        //      width: 1024,
        //      height: 768,
        //      minWidth: 400,
        //      minHeight: 200,
        //      resizable: true,
        //      maximize: true
        //  }
            })
        ])
    }
};
export default config;
MacFJA commented 1 year ago

The Neutralino adapter is using the @sveltejs/adapter-static under the hood. And suppose that your application is fully static (no Server Side rendering and no server action/code)

But it would be easy to add the possibility to pass custom configuration to the @sveltejs/adapter-static. Maybe something like that:

neutralinoAdapter({
    name: 'APP',
    icon: 'static/favicon.png',
    applicationId: 'de.APP.com',
    output: 'build/neutralino',
    window: {
        width: 1024,
        height: 768,
        minWidth: 400,
        minHeight: 200,
        resizable: true,
        maximize: true
    },
    staticAdapter: {
        strict: false,
        fallback: 'index.html',
        precompress: false
        // ...
        // but `pages` and `assets` won't be configurable as the Neutralino adapter need to have control on them
    }
})
aleritty commented 1 year ago

Sorry, maybe I wasn't clear in the description.

My application needs "strict: false" in the staticAdapter. If I use only the static adapter everything builds

If I use staticAdapter + neutralinoAdapter, then the staticAdapter will fail. Please check the copied configurations.

I will prepare also a test repository to replicate the problem