Skip to content

Commit faa9413

Browse files
committed
fix: update for manifest v3
1 parent 074dd3e commit faa9413

File tree

6 files changed

+8548
-49
lines changed

6 files changed

+8548
-49
lines changed

constants.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ const constants = {
99
edge:
1010
"EDGE_STORE_URL",
1111
},
12+
1213
// put extension key here if required which would only be used in development mode
13-
key: "SSH_PUBLIC_KEY", // gather it from extension store
14+
key: "-----BEGIN PUBLIC KEY-----\n" +
15+
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp2M7a3NkVXE+hEmPzpfy\n" +
16+
"L5xQKCPiGotVzC1Ep8XSfimPS5hXw0MBnkP2pxJKwHXeFQDthz6bx837aTwenw2L\n" +
17+
"kmaSwzJK5cUBcAzvbx4H1WOyXaZO1G4/iIDP0A0L1KXu/gCIyYpPXXwLtbqXp78s\n" +
18+
"6EpEqJOepSDdkoOKg/ejZq+/gpbVfY4k9CMprX2Jylq+orXrViH3jdVic3QXZDdp\n" +
19+
"mNRTjmUmJii1DTCxYh9207YSVe3bfY1TGQjKx2GcUAGiJBhNwcgFqkdVdkArGuJs\n" +
20+
"zuPO5HthTF3u6AouhuLnIWOSHiXZg8KL/g5Jv2t9XuJuth2mzcrXlFVYtCd3k5+q\n" +
21+
"mQIDAQAB\n" +
22+
"-----END PUBLIC KEY-----", // gather it from extension store
1423
},
1524
contentScript: {
1625
mountId: generateGuid(),
@@ -35,4 +44,3 @@ const constants = {
3544
};
3645

3746
module.exports = constants;
38-

package.json

+25-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
22
"name": "browser-extension-boilerplate",
3-
"version": "0.0.1",
3+
"version": "0.0.0",
44
"description": "",
55
"homepage": "https://fxnoob.github.io/chrome-extension-boilerplate",
66
"scripts": {
7-
"build:tailwind": "tailwindcss build src/styles/style.css -o dist/style.css",
7+
"build:tailwind": "tailwindcss build -i src/styles/style.css -o dist/style.css",
88
"watch:tailwind": "chokidar 'src/styles/*.css' -c 'yarn build:tailwind'",
99
"prestart": "yarn build:tailwind",
1010
"prebuild": "yarn rm && yarn build:tailwind",
1111
"rm": "rm -rf dist/",
12-
"rm:zip": "rm dist.zip",
13-
"dev:chromium": "yarn build:tailwind && webpack --stats-children --progress --config chromium.webpack.js --mode=development",
12+
"rm:extZip": "rm ext.zip",
13+
"dev:chromium": "concurrently --kill-others \"npm run watch:tailwind\" \"npm run webpack:chromium:dev\"",
14+
"webpack:chromium:dev": "webpack --watch --progress --config chromium.webpack.js --mode=development",
1415
"dev:firefox": "yarn build:tailwind && webpack --watch --progress --config firefox.webpack.js --mode=development",
15-
"build:chromium": "yarn build:tailwind && webpack --progress --config chromium.webpack.js --mode=production",
16+
"build:chromium": "webpack --progress --config chromium.webpack.js --mode=production && yarn build:tailwind",
1617
"build:firefox": "yarn build:tailwind && webpack --progress --config firefox.webpack.js --mode=production",
1718
"jsdoc": "jsdoc src -r",
1819
"deploy_jsdoc": "yarn jsdoc && gh-pages -d out",
@@ -42,15 +43,17 @@
4243
"@babel/runtime": "7.20.0",
4344
"arg": "5.0.2",
4445
"babel-eslint": "10.1.0",
45-
"babel-loader": "8.2.5",
46+
"babel-loader": "^8.2.2",
47+
"babel-minify": "^0.5.1",
4648
"brotli-webpack-plugin": "1.1.0",
4749
"chai": "4.3.6",
4850
"chalk": "4.1.2",
4951
"chokidar": "^3.5.3",
5052
"chokidar-cli": "2.1.0",
51-
"concurrently": "5.3.0",
52-
"copy-webpack-plugin": "5.1.2",
53-
"css-loader": "6.7.1",
53+
"clean-webpack-plugin": "^4.0.0",
54+
"concurrently": "^8.2.0",
55+
"copy-webpack-plugin": "^9.0.1",
56+
"css-loader": "^6.2.0",
5457
"dotenv": "8.6.0",
5558
"esbuild-loader": "2.20.0",
5659
"eslint": "7.32.0",
@@ -60,24 +63,33 @@
6063
"esm": "3.2.25",
6164
"exec-sh": "0.3.6",
6265
"execa": "6.1.0",
66+
"file-loader": "^6.2.0",
67+
"fs-extra": "^10.0.0",
68+
"html-loader": "^2.1.2",
69+
"html-webpack-plugin": "^5.3.2",
6370
"husky": "3.1.0",
6471
"inquirer": "7.3.3",
6572
"jsdoc": "3.6.11",
6673
"jsonfile": "6.1.0",
6774
"node-google-translate-skidz": "1.1.2",
6875
"prettier": "1.18.2",
6976
"pretty-quick": "2.0.2",
70-
"style-loader": "3.3.1",
77+
"sass": "^1.37.5",
78+
"sass-loader": "^12.1.0",
79+
"source-map-loader": "^3.0.0",
80+
"style-loader": "^3.2.1",
7181
"tailwindcss": "^3.2.4",
72-
"webpack": "5.74.0",
73-
"webpack-cli": "4.10.0"
82+
"webpack": "^5.48.0",
83+
"webpack-cli": "^4.7.2",
84+
"webpack-dev-server": "^3.11.2"
7485
},
7586
"dependencies": {
7687
"@emotion/react": "^11.10.5",
7788
"@emotion/styled": "^11.10.5",
7889
"@mui/material": "^5.10.13",
7990
"react": "^18.2.0",
8091
"react-dom": "^18.2.0",
81-
"react-frame-component": "^5.2.3"
92+
"react-frame-component": "^5.2.3",
93+
"source-map-loader": "^4.0.1"
8294
}
8395
}

src/option-page/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function App() {
22
return <div>Options</div>;
3-
}
3+
}

src/option-page/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ReactDOM from "react-dom";
1+
import ReactDOM from "react-dom/client";
22
import App from "./App";
33
const root = ReactDOM.createRoot(document.getElementById('app'));
44
root.render(<App />);

webpack.config.js

+65-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const webpack = require("webpack");
2-
const { ESBuildPlugin, ESBuildMinifyPlugin } = require("esbuild-loader");
32
const CopyWebpackPlugin = require("copy-webpack-plugin");
43
const dotenv = require("dotenv").config({ path: __dirname + "/.env" });
5-
const { manifestTransform } = require("./scripts/transform");
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const path = require("path");
6+
const { manifestTransform } = require('./scripts/transform');
7+
8+
const buildDirectory = 'dist';
69

710
module.exports = (env, options) => {
811
return {
@@ -12,19 +15,39 @@ module.exports = (env, options) => {
1215
popup: "./src/popup-page/index.js",
1316
option: "./src/option-page/index.js"
1417
},
18+
devtool: 'cheap-module-source-map',
1519
module: {
1620
rules: [
1721
{
1822
test: /\.(js|jsx)$/,
19-
exclude: /node_modules/,
2023
use: [
21-
'babel-loader',
22-
"eslint-loader"
23-
]
24+
{
25+
loader: 'source-map-loader',
26+
},
27+
{
28+
loader: 'babel-loader',
29+
},
30+
],
31+
exclude: /node_modules/,
2432
},
2533
{
26-
test: /\.css$/,
27-
use: ["style-loader", "css-loader?modules"]
34+
// look for .css or .scss files
35+
test: /\.(css|scss)$/,
36+
// in the `src` directory
37+
use: [
38+
{
39+
loader: 'style-loader',
40+
},
41+
{
42+
loader: 'css-loader',
43+
},
44+
{
45+
loader: 'sass-loader',
46+
options: {
47+
sourceMap: true,
48+
},
49+
},
50+
],
2851
},
2952
{
3053
test: /\.(gif|png|jpe?g|svg)$/i,
@@ -36,39 +59,49 @@ module.exports = (env, options) => {
3659
extensions: ['.mjs', '*', '.js', '.jsx', '.css', '.json'],
3760
},
3861
output: {
39-
path: __dirname + "/dist",
62+
path: __dirname + "/" + buildDirectory,
4063
publicPath: "/",
4164
filename: "[name].bundle.js"
4265
},
43-
optimization: {
44-
minimize: true,
45-
minimizer: [new ESBuildMinifyPlugin()]
46-
},
4766
plugins: [
48-
new ESBuildPlugin(),
49-
new CopyWebpackPlugin(
50-
[
51-
{ from: "./src/popup-page/popup.html", force: true },
52-
{ from: "./src/option-page/option.html", force: true },
53-
{ from: "./src/app/", force: true }
54-
],
55-
{}
56-
),
67+
new webpack.ProgressPlugin(),
5768
new webpack.DefinePlugin({
5869
"process.env": JSON.stringify({ ...options, ...dotenv.parsed })
5970
}),
60-
new CopyWebpackPlugin([
61-
{
62-
from: "./src/app/manifest.json",
63-
force: true,
64-
transform(content, path) {
65-
return manifestTransform(content, path, options);
66-
}
67-
}
68-
])
71+
new CopyWebpackPlugin({
72+
patterns: [
73+
{
74+
from: './src/app',
75+
to: path.join(__dirname, buildDirectory),
76+
force: true,
77+
},
78+
{
79+
from: './src/app/manifest.json',
80+
to: __dirname + '/' + buildDirectory,
81+
force: true,
82+
// eslint-disable-next-line no-unused-vars
83+
transform: function (content, path) {
84+
// generates the manifest file using the package.json information
85+
return manifestTransform(content, path, options);
86+
},
87+
},
88+
],
89+
}),
90+
new HtmlWebpackPlugin({
91+
template: './src/option-page/option.html',
92+
filename: 'option.html',
93+
chunks: ['options'],
94+
cache: false,
95+
}),
96+
new HtmlWebpackPlugin({
97+
template: './src/popup-page/popup.html',
98+
filename: 'popup.html',
99+
chunks: ['popup'],
100+
cache: false,
101+
})
69102
],
70103
devServer: {
71-
contentBase: "./dist",
104+
contentBase: "./" + buildDirectory,
72105
hot: true
73106
},
74107
};

0 commit comments

Comments
 (0)