Giter VIP home page Giter VIP logo

webpack-user-script-template's Introduction

This is a project help you build userscript with webpack

Just use this git repo as a template.

中文说明

dev

  1. Allow Tampermonkey's access to local file URIs tampermonkey/faq
  2. install deps with npm i or npm ci.
  3. npm run dev to start your development.

Now you will see 2 files in ./dist/

  • dist/index.dev.user.js: You should install this userscript in your browser. It's a simple loader that load dist/index.debug.js on matched web page.
  • dist/index.debug.js: This is the development build with eval-source-map. It will be automatically loaded by dist/index.dev.user.js via @require file://.../dist/index.debug.js metadata, Don't add it to your userscript manager.
  1. edit src/index.ts, you can even import css or less files. You can use scss if you like.
  2. go wo https://www.example.com/ and open console, you'll see it's working.

livereload is default enabled, use this Chrome extension

NOTICE

Everytime you change your metadata config, you'll have to restart webpack server and install newly generated dist/index.dev.user.js UserScript in your browser again.

used package

If you prefer some other bundler like rollup, you can use some of these packages directly.

userscript-metadata-generator

gm-fetch

userscript-metadata-webpack-plugin

Cross Site Request

you can call GM.xmlHttpRequest directly or use a fetch API based on GM.xmlHttpRequest https://github.com/Trim21/gm-fetch

TypeScript

use typescript as normal, see example

dependencies

There are two ways to using a package on npm.

UserScript way

like original UserScript way, you will need to add them to your user script metadata's require section , and exclude them in config/webpack.config.base.cjs

Webpack way

just install packages with npm and import them in your code, webpack will take care them.

Build

npm run build

dist/index.prod.user.js is the final script. you can manually copy it to greasyfork for deploy.

Minify

There is a limitation in greasyfork, your code must not be obfuscated or minified.

If you don't need to deploy your script to greasyfork, enable minify as you like.

automatically Deploy

github actions will deploy production userscript to gh-pages branch.

example

deployed

You can auto use greasyfork's auto update function.

Q&A

you may find enabling source map not working well in production code, because Tampermonkey will add extra lines (all your @require) before your script. I don't know if there is a good fix for this, You need to use webpack config devtool with eval prefix to make it work as expected, so source map is disabled in this production build.

https://webpack.js.org/configuration/devtool/#development

webpack-user-script-template's People

Contributors

renovate[bot] avatar itsbrex avatar

Watchers

 avatar

webpack-user-script-template's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/jquery to ^3.5.30
  • Update dependency css-loader to v7
  • Update dependency husky to v9
  • Update dependency less-loader to v12
  • Update dependency lint-staged to v15
  • Update dependency prettier to v3
  • Update dependency style-loader to v4
  • Update peaceiris/actions-gh-pages action to v4
  • Lock file maintenance
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yaml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/deploy-preview.yaml
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
.github/workflows/deploy.yaml
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
npm
package.json
  • @trim21/gm-fetch ^0.1.15
  • jquery ^3.7.1
  • @types/greasemonkey ^4.0.7
  • @types/jquery ^3.5.29
  • @types/node ^18.16.14
  • browserslist ^4.22.2
  • cross-env ^7.0.3
  • css-loader ^6.7.4
  • husky ^8.0.3
  • less ^4.2.0
  • less-loader ^11.1.0
  • lint-staged ^13.2.2
  • prettier ^2.8.8
  • style-loader ^3.3.4
  • ts-loader ^9.4.2
  • typescript ^5.0.4
  • userscript-metadata-webpack-plugin ^0.4.0
  • webpack ^5.83.1
  • webpack-bundle-analyzer ^4.8.0
  • webpack-cli ^5.1.1
  • webpack-livereload-plugin ^3.0.2
  • webpack-merge ^5.8.0
  • webpack-sources ^3.2.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.