Git Product home page Git Product logo

Comments (4)

skullpsg avatar skullpsg commented on August 24, 2024

It looks, for ts file it is taking video/mp2t as content type. How to fix this?

from web.

bashmish avatar bashmish commented on August 24, 2024

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.

bashmish avatar bashmish commented on August 24, 2024

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.

skullpsg avatar skullpsg commented on August 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.