Giter VIP home page Giter VIP logo

obs-ninja-multiscene's Introduction

browser-extension-template

Barebones boilerplate with webpack, options handler and auto-publishing.

Sample extension output

Features

This extension template is heavily inspired by refined-github, notifier-for-github, and hide-files-on-github browser extensions. You can always refer to these browser extensions' source code if you find anything confusing on how to create a new extension.

How to use this template

Click Use this template and make a copy of your own. ๐Ÿ˜‰

Configuration

The extension doesn't target any specific ECMAScript environment or provide any transpiling by default. The extensions output will be the same ECMAScript you write. This allows us to always target the latest browser version, which is a good practice you should be following.

Webpack

Transpiling using Babel

The template bakes in a pretty basic webpack config, with no transpiling. To setup transpiling using Babel follow the following configuration steps.

  1. Install Babel packages and respective loader for webpack.

    npm i --save-dev @babel/core @babel/preset-env babel-loader
  2. In webpack.config.js, add the following rule to process JS files.

    module: {
    	rules: [
    		{
    			test: /\.js$/,
    			exclude: /node_modules/,
    			loader: 'babel-loader'
    		}
    	]
    }
  3. Target respective browsers using .babelrc.

    {
    	"presets": [
    		[
    			"@babel/preset-env",
    			{
    				"targets": {
    					"chrome": "74",
    					"firefox": "67"
    				}
    			}
    		]
    	]
    }

Extracting CSS

If you will be writing any code that will be importing CSS files from JS files, then you will be needing mini-css-extract-plugin to extract this imported CSS into its own file.

  1. Install the webpack plugin.

    npm i --save-dev mini-css-extract-plugin
  2. Modify the webpack config as mentioned to let this plugin handle CSS imports.

    // Import plugin
    const MiniCssExtractPlugin = require('mini-css-extract-plugin');
    
    // Under `module.rules`
    {
    	test: /\.css$/,
    	use: [
    		MiniCssExtractPlugin.loader,
    		'css-loader'
    	]
    }
    
    // Under `plugins`
    new MiniCssExtractPlugin({
    	filename: 'content.css'
    })

TypeScript

TypeScript and Babel configs conflict each other, so you can only use one of these configuration types at any point.

  1. Install TypeScript and respective loader for webpack

    npm i --save-dev typescript ts-loader @types/firefox-webext-browser
  2. Use the following webpack rule in the config file.

    {
    	test: /\.(js|ts|tsx)$/,
    	loader: 'ts-loader',
    	exclude: /node_modules/
    },
  3. Use the following as tsconfig.json, uses sindresorhus/tsconfig (install it as dependecy before using).

    {
    	"extends": "@sindresorhus/tsconfig",
    	"compilerOptions": {
    		"target": "esnext",
    		"declaration": false
    	},
    	"include": [
    		"source"
    	]
    }

TypeScript requires additional configuration depending on how you set it up, like linting.

Auto-syncing options

Options are managed by fregante/webext-options-sync, which auto-saves and auto-restores the options form, applies defaults and runs migrations.

Publishing

It's possible to publish to both the Chrome Web Store and Mozilla Addons at once by creating these ENV variables:

  1. CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN from Google APIs.
  2. WEB_EXT_API_KEY, and WEB_EXT_API_SECRET from AMO.

And then running:

npm run release

This will:

  1. Build the extension
  2. Create a version number based on the current UTC time, like 19.6.16.428 and sets it in the manifest.json
  3. Deploy it to both stores

Auto-publishing

Thanks to the included GitHub Action Workflows, if you set up those ENVs in the repo's Settings, the deployment will automatically happen:

  • on a schedule, by default every week (but only if there are any new commits in the last tag)
  • manually, by clicking "Run workflow" in the Actions tab.

License

This browser extension template is released under CC0 and mentioned below. There is no license file included in here, but when you clone this template, you should include your own license file for the specific license you choose to use.

Credits

Extension icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY.

Extensions created using this template

License

CC0

obs-ninja-multiscene's People

Contributors

gbdlin avatar

Watchers

 avatar  avatar

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.