Menu

#1355 Proposal: Add minimal extension sample where `content_scripts` import shared logic

open
nobody
None
2025-01-06
2024-11-21
Anonymous
No

Originally created by: hirehamir

It'd be nice if this sample used TypeScript.

Discussion

  • Anonymous

    Anonymous - 2024-11-21

    Originally posted by: oliverdunk

    Hi @hamirmahal, did you have a particular implementation in mind? At the moment, we don't have a good way of doing this, so my suggestion would be to use a bundler to generate a single file at build time. In the future, we'd like to make that easier - there are some workarounds some tooling uses based on web_accessible_resources but this isn't ideal and probably isn't something we would encourage.

    As for TypeScript, we generally try to avoid that in samples as it adds an extra layer for developers to understand - I think one or two TypeScript samples wouldn't be a bad idea though.

     
  • Anonymous

    Anonymous - 2024-11-21

    Originally posted by: hirehamir

    Hello @oliverdunk, thanks for the quick response. Matching developer expectations as much as possible would be ideal.

    If

    import sharedLogic from './sharedLogic';
    

    "just worked" in contentScript1.js and contentScript2.js, that'd be great.

    Which bundler do you recommend for someone prioritizing type safety, ease of use, and simplicity?

     
  • Anonymous

    Anonymous - 2025-01-06

    Originally posted by: oliverdunk

    Definitely agreed that it would be nice to support an import like that. Unfortunately, it isn't something we support today.

    Which bundler do you recommend for someone prioritizing type safety, ease of use, and simplicity?

    All bundlers are good for different reasons - we don't have a standard recommendation so feel free to try a few :)

     

Log in to post a comment.