open-wc / open-wc-starter-app

Starter app based on Open Web Components Recommendations
https://open-wc.org/
93 stars 14 forks source link

Problem with a SPA and owc-dev-server (--app-index) #9

Open frederikhors opened 5 years ago

frederikhors commented 5 years ago

I'm having troubles using the default start script in package.json.

The default one is:

"start": "owc-dev-server --open ./src"

but I'm building a SPA (single page application) and I changed it to:

"start": "owc-dev-server --app-index ./src/index.html"

adding also in index.html's <head>:

<base href="/">

But now the problem is:

<script type="module" src="./my-app.js"></script>

In browser's console I got this error:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

I need to change it like this to work:

<script type="module" src="./src/my-app.js"></script>

adding ./src before /my-app.js.

The problem now is using npm run build: it doesn't find my-app.js during build.

I'm wrong somewhere, but where?