Comments (4)
It looks, for ts file it is taking video/mp2t as content type. How to fix this?
from web.
Is babel configured correctly?
In our docs I see default.default
export being used https://modern-web.dev/guides/dev-server/using-plugins/#babel which seems like the babel module has no proper ESM export
import { fromRollup } from '@web/dev-server-rollup';
import rollupBabel from '@rollup/plugin-babel';
// note that you need to use `.default` for babel
const babel = fromRollup(rollupBabel.default);
from web.
It looks, for ts file it is taking video/mp2t as content type. How to fix this?
If you need this only in dev mode, you can write a simple WDS plugin to serve .ts
files as text/javascript
using this hook:
https://modern-web.dev/docs/dev-server/writing-plugins/hooks/#hook-resolvemimetype
I think we even mention it in docs here: https://modern-web.dev/docs/dev-server/writing-plugins/hooks/#hook-transform
If you are transforming non-standard file types, you may also need to include a resolveMimeType hook. A good example of this is .ts files, which in Koa defaults to a streaming video.
If you also need this to be compiled for production, make sure to bundle TS files into JS chunks or convert them to JS extension if you keep files paths as is, in general make sure that non-standard extensions are not in your production bundle.
Plugins like this can help to handle TS in general https://modern-web.dev/docs/dev-server/plugins/esbuild/
from web.
@bashmish I have added mime type resolver like this:
import path from "path";
export default function resolveMimeType(url) {
// Define a lookup table mapping file extensions to MIME types
const mimeTypes = {
html: "text/html; charset=utf-8",
htm: "text/html; charset=utf-8",
js: "application/javascript; charset=utf-8",
css: "text/css; charset=utf-8",
ts: "js",
};
// Extract the file extension from the URL
const key = path.extname(url) || "";
// Return the corresponding MIME type from the lookup table
let result = mimeTypes[key.startsWith(".") ? key.slice(1) : key];
if (result == undefined) {
return {};
}
return result;
}
It seems to resolving ts loading problem.
from web.
Related Issues (20)
- Coverage not generated when we are using babel with custom browser [locally]
- Test Runner config rootPath is resolved relative to cwd, not the path of the config
- Test Runner 'manual' mode import path is not relative to rootPath
- Update @web/dev-server-esbuild dependencie esbuild to v0.21 HOT 2
- Contributing guide uses npm, GitHub actions use Yarn HOT 1
- [@web/test-runner] Tests do not finish when asserting frozen objects
- Node tests failing on Windows
- Out-of-date instruction to use run-playwright-tests HOT 1
- @web/rollup-plugin-import-meta-assets: Types not part of the exports declaration in package.json
- How can I set the browser's locale when using the Web Test Runner with Playwright?
- TypeError: URL.canParse is not a function HOT 1
- [dev-server] CVE-2024-29415: "ip SSRF improper categorization in isPublic" HOT 16
- Mermaid Library issue in web-dev-server HOT 3
- [dev-server-core | dev-server-hmr] CVE-2024-37890: "ws affected by a DoS when handling a request with many HTTP headers" HOT 1
- [@web/dev-server-rollup] Higher version of whatwg-url HOT 1
- [@web/test-runner-browserstack] + [@web/dev-server-legacy]: issues when using BrowserStack launcher for targeting certain older devices
- wtr: fails to compile standard decorators HOT 2
- question about packages/dev-server-import-maps HOT 3
- Support for Consumer Driven Contract creation using PactJS
- How to import HTML file using esbuild's text loader?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web.