-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.js
executable file
·118 lines (116 loc) · 3.29 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const dotenv = require("dotenv").config({ path: __dirname + "/.env" });
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require("path");
const { manifestTransform } = require('./scripts/transform');
const ExtReloader = require('@reorx/webpack-ext-reloader');
const buildDirectory = 'dist';
module.exports = (env, options) => {
return {
entry: {
content_script: "./src/content-scripts/index.js",
background: "./src/background.js",
popup: "./src/popup-page/index.js",
option: "./src/option-page/index.js"
},
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: [
{
loader: 'source-map-loader',
},
{
loader: 'babel-loader',
},
],
exclude: /node_modules/,
},
{
// look for .css or .scss files
test: /\.(css|scss)$/,
// in the `src` directory
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
type: 'asset/resource'
}
]
},
resolve: {
extensions: ['.mjs', '*', '.js', '.jsx', '.css', '.json'],
},
output: {
path: __dirname + "/" + buildDirectory,
publicPath: "/",
filename: "[name].bundle.js"
},
plugins: [
new ExtReloader({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: { // The entries used for the content/background scripts or extension pages
contentScript: 'content_script',
background: 'background',
extensionPage: ['popup', 'option', /* and so on ... */],
}
}),
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
"process.env": JSON.stringify({ ...options, ...dotenv.parsed })
}),
new CopyWebpackPlugin({
patterns: [
{
from: './src/app',
to: path.join(__dirname, buildDirectory),
force: true,
},
{
from: './src/app/manifest.json',
to: __dirname + '/' + buildDirectory,
force: true,
// eslint-disable-next-line no-unused-vars
transform: function (content, path) {
// generates the manifest file using the package.json information
return manifestTransform(content, path, options);
},
},
],
}),
new HtmlWebpackPlugin({
template: './src/option-page/option.html',
filename: 'option.html',
chunks: ['options'],
cache: false,
}),
new HtmlWebpackPlugin({
template: './src/popup-page/popup.html',
filename: 'popup.html',
chunks: ['popup'],
cache: false,
})
],
devServer: {
contentBase: "./" + buildDirectory,
hot: true
},
};
};