Just use this git repo as a template.
- Allow Tampermonkey's access to local file URIs tampermonkey/faq
- install deps with
npm i
ornpm ci
. npm run dev
to start your development.- open
webpack-userscript-template/dist/index.dev.user.js
in your Chrome and install it with your userscript manager.
this userscript's meta contains // @require file://path/to/dist/index.debug.user.js
,
which take src/index.ts as entry point.
Everytime you change your metadata config, you'll have to restart webpack watch server and install new UserScript in your browser again, because Tampermonkey don't read it from dist everytime.
- edit src/index.ts, you can even import css or less files. You can use scss if you like.
- go wo https://www.example.com/ and open console, you'll see it's working.
livereload is default enabled, use this Chrome extension
You will also see a index.debug.user.js
file in dist
directory,
this is a development usage file with eval-source-map
for better browser error message.
use typescript as normal, see example
There are two ways to using a package on npm.
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
just install a package and import it in your js file. webpack will pack them with in your final production js file.
npm run build
dist/index.prod.user.js
is the final script. you can manually copy it to greaskfork for deploy.
There is a limit in greasyfork, your code must not be obfuscated or minified.
github actions will deploy production userscript to gh-pages branch.
You can auto use greasyfork's auto update function.