samrum / vite-plugin-web-extension

A vite plugin for generating cross browser platform, ES module based web extensions.
MIT License
323 stars 33 forks source link

feat: support for safari web extensions #124

Closed juliendargelos closed 8 months ago

juliendargelos commented 1 year ago

I'm not sure this falls within the scope of this plugin, but for my own use I implemented an additional build process to create Safari web extensions. It relies on the xcode command line tools to convert the existing output to a macOS app embedding the extension. It is generated during the writeBundle hook, and outputted aside the original dist folder.

I believe my addition isn't that clean neither bulletproof right now, but it could be a starting point if you want to provide this feature.

ugurkellecioglu commented 8 months ago

Hi @juliendargelos thanks for the feature. I'd like to try this but I'm not sure how to use this addition in my existing extension. Can you help / documentate how we can use this?

samrum commented 8 months ago

Sorry for the delayed response!

I appreciate the PR, but I do think it's a little out of scope for what I'd want the plugin to be responsible for handling.

Neat implementation, though.

juliendargelos commented 8 months ago

Hi @juliendargelos thanks for the feature. I'd like to try this but I'm not sure how to use this addition in my existing extension. Can you help / documentate how we can use this?

@ugurkellecioglu You can try it out using the safari option:

webExtension({
  safari: true
})

https://github.com/juliendargelos/vite-plugin-web-extension/blob/66349c716dfa8b7ea6ddb99dd4ac8cbe1d7271a5/types/index.d.ts#L45-L49

interface ViteWebExtensionOptions {
  // ...

  /**
   * Enables and configures Safari build.
   * Default: false
   */
  safari?: boolean | SafariBuildOptions;

  // ...
}

https://github.com/juliendargelos/vite-plugin-web-extension/blob/66349c716dfa8b7ea6ddb99dd4ac8cbe1d7271a5/types/index.d.ts#L71-L95

export interface SafariBuildOptions {
  /**
   * Safari extension build output
   * Default: vite output dir with a `-safari` suffix
   */
  dir?: string;

  /**
   * Name of the app
   * Default: name provided in the manifest
   */
  appName?: string;

  /**
   * Bundle identifier to build the app with
   * Default: undefined
   */
  bundleIdentifier?: string;

  /**
   * Build the app using objective-c instead of swift
   * Default: false
   */
  objc?: boolean;
}
ugurkellecioglu commented 8 months ago

Sorry for the delayed response!

I appreciate the PR, but I do think it's a little out of scope for what I'd want the plugin to be responsible for handling.

Neat implementation, though.

Hi @samrum , I really appreciate for this beautiful work you do but can you please explain why this PR is out of scope?

This whole project is about creating cross platform extensions right? Safari is one of them. I highly believe that (the PR) is a good feature to have. Is there a chance you to consider the decision you made?

juliendargelos commented 8 months ago

Sorry for the delayed response!

I appreciate the PR, but I do think it's a little out of scope for what I'd want the plugin to be responsible for handling.

Neat implementation, though.

Hi @samrum , I really appreciate for this beautiful work you do but can you please explain why this PR is out of scope?

This whole project is about creating cross platform extensions right? Safari is one of them. I highly believe that (the PR) is a good feature to have. Is there a chance you to consider the decision you made?

I can understand why this feature would not fall within the scope of this plugin. It heavily relies on platform specific tools (MacOs XCode Command Line Tools), so for instance, this would not work on Windows or Linux distributions.

Also, my implementation is really a draft, it worked for me but, in some other cases, it may fail or behave strangely. So not ready for a release.

Nothing stops you from using it though ! Just clone the branch, build it and use the configuration I mentionned above :)