Search code examples
svelterollup

Rollup does not compile HTML from Svelte


I'm currently trying to integrate svelte into another project of mine, but I'm running into an issue that I think might have something to do with rollup or rather the svelte plugin for rollup.

What might be important to know before: I want to use typescript as well. (So before everything, I always ran node scripts/setupTypeScript.js)

The problem is that rollup, seemingly at random, does not generate the HTML and CSS files from the svelte-source files.

I tried explicitly including the source files in the rollup.config.js:

svelte({
    include: "src/**/*.svelte",
    preprocess: sveltePreprocess({ sourceMap: !production }),
    compilerOptions: {
        // enable run-time checks when not in production
        dev: !production
    }
}),

and also replacing the

import App from "./App.svelte

with

const App = require("./App.svelte") 

but no luck.

When I run rollup -c I always just get the bundle.js and bundle.js.map in the public/build folder, but no HTML or CSS files.

What am I missing?

The project folder looks like this: (After I run rollup -c)

│   .gitignore
│   package-lock.json
│   package.json
│   README.md
│   rollup.config.js
│   tsconfig.json
│
├───.vscode
│       extensions.json
│
├───node_modules
│       [...]
│
├───public
│   └───build
│           bundle.js
│           bundle.js.map
│
└───src
        App.svelte
        global.d.ts
        main.ts

Solution

  • So I think I found a solution.

    I think the problem was, that I always deleted the public folder when I ran a fresh compile, because I thought all it contained was files that the compiler generates anyway.

    I guess that isn't quite the case.

    After I copied a fresh public folder out of another template, it now seems to work.

    Altough I still don't fully understand why this is necessary, because the template-ZIP itself doesn't contain a public folder. It also is only generated after I first ran npm run build. So for some reason, at some point, the compiler doesn't fully generate that anymore.