- Hot-reload
- it does not preserve state it uses:
chrome.runtime.reloadandchrome.tabs.reload- websocket
- hot-reload.js
- socket.script.js
- it does not preserve state it uses:
- Typescript
- Webpack builder
- Tailwind
postcss
-
The folder structure is un-opinionated, I just arrange the folder base on my likings
- 📁 css
- all styles css
- 📁 .dist-build
- This Is Where The Compiled Typescript, And Files Goes In
- 📁 .production-build
- production ready using webpack, does not include
zippedversion
- production ready using webpack, does not include
- 📁 html
- all the static html of your extension
- popup.html
- ....
- all the static html of your extension
- 📁 scripts
- all your scripts
- content scripts
- background scripts
- popup scripts
- all your scripts
- 📁 lib-js
- This is for already build 3rd party libraries in vanila javasript such as minified/uglified jquery, tailwind, and others
- I suggest do not put any
.tsfiles on this folder as it is ignored by typescript only put "optimized" version of.jsfile here
- 📁 utils/socket.script.js
- This is for development, it connects hot-reload.js to socket.script.js via websocket then socket.script.js communicate with background script to do
chrome.runtime.reloadandchrome.tabs.reload - This will not be included when you build your project
- This is for development, it connects hot-reload.js to socket.script.js via websocket then socket.script.js communicate with background script to do
- 📁 css
-
⚙️ manifest.json - Without this the project wont load on browser, lastest version is manifest v3 - check https://developer.chrome.com/docs/extensions/reference/manifest
You can make as much folder as you want you just need to configure
tsconfig.jsonand webpack.config.js
-
Install Dev Depencies
- yarn install
-
yarn dev
.dev-buildwill be created, use this one toload unpackedon the browser- Hot reload ready using websocket
-
Go to chrome://extensions/ and Enable Developer mode
- Click
Load unpackedand load"your project directory"/src
YOU NEED TO MANUALLY RELOAD IT FIRST TO ESTABLISH
WSCONNECTION (WORKING ON THIS ONE SO YOU WONT NEED TO MANUALLY RELOAD AT FIRST)YOU ALSO NEED TO ENABLE
DEVELOPER MODEFIRST
- Click
-
yarn build
-
This uses webpack you can configure it in
webpack/webpack.common.config.jsandwebpack/webpack.prod.js-You need to commment several codes when you run build: -
You need to comment several codes before running
yarn buildas all this code is for development purpose only- at background.script.ts
>chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { > /***COMMENT THIS LINES OF CODES WHEN YOU BUILD THE PROJECT FOR PRODUCTION SO IT WILL NOT BE INCLUDED*/ > if (request.type === "reload") { > } > /************************************************************************/ >}); - at manifest.json
{ "matches": ["<all_urls>"], "js": ["dist/utils/socket.script.js"] },
- at background.script.ts
-
-
yarn build-vite
- This uses vite but there is problem with copying of the folders,
vite.cofig.js🚧- refer to issue #1 - vite
- This uses vite but there is problem with copying of the folders,