-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathwebpack.common.js
More file actions
128 lines (118 loc) · 3.76 KB
/
webpack.common.js
File metadata and controls
128 lines (118 loc) · 3.76 KB
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
119
120
121
122
123
124
125
126
127
128
const path = require('path');
const glob = require('glob');
const webpack = require('webpack');
const DotenvPlugin = require('dotenv-webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const contentScripts = glob.sync('./src/contentscripts/**/*.js')
.reduce((acc, path) => {
const entry = path.replace(/src\/(.*)\.js/, '$1');
acc[entry] = path;
return acc;
}, {});
const injectScripts = glob.sync('./src/injectscripts/**/*.js')
.reduce((acc, path) => {
const entry = path.replace(/src\/(.*)\.js/, '$1');
acc[entry] = path;
return acc;
}, {});
const pagesScripts = [
...glob.sync('./src/pages/*.js'),
'./src/pages/tasking/main.js',
].reduce((acc, path) => {
const entry = path.replace(/src\/pages\/(.*)\.js/, 'pages/$1');
acc[entry] = path;
return acc;
}, {});
const myAvailContentScripts = glob.sync('./src/myAvailability/src/contentscripts/**/*.js')
.reduce((acc, path) => {
const entry = path.replace(/src\/myAvailability\/src\/(.*)\.js/, 'myAvailability/$1');
acc[entry] = path;
return acc;
}, {});
const myAvailInjectScripts = glob.sync('./src/myAvailability/src/injectscripts/**/*.js')
.reduce((acc, path) => {
const entry = path.replace(/src\/myAvailability\/src\/(.*)\.js/, 'myAvailability/$1');
acc[entry] = path;
return acc;
}, {});
const myAvailPagesScripts = glob.sync('./src/myAvailability/src/pages/*.js')
.reduce((acc, path) => {
const entry = path.replace(/src\/myAvailability\/src\/pages\/(.*)\.js/, 'myAvailability/pages/$1');
acc[entry] = path;
return acc;
}, {});
module.exports = {
entry: {
background: './src/background.js',
...contentScripts,
...injectScripts,
...pagesScripts,
...myAvailContentScripts,
...myAvailInjectScripts,
...myAvailPagesScripts
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
use: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
// Force webpack to consume the unbundled lib/ sources of leaflet-geosearch
// instead of the pre-bundled dist/geosearch.module.js. The pre-bundle
// inlines @googlemaps/js-api-loader code (containing the remote URL
// "https://maps.googleapis.com/maps/api/js") which violates MV3 CSP.
// Using lib/ lets tree-shaking drop unused providers and lets the
// NormalModuleReplacementPlugin below intercept the separate
// @googlemaps/js-api-loader import.
'leaflet-geosearch/dist/geosearch.css': path.resolve(
__dirname,
'node_modules/leaflet-geosearch/dist/geosearch.css'
),
'leaflet-geosearch$': path.resolve(
__dirname,
'node_modules/leaflet-geosearch/lib'
),
},
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
plugins: [
// leaflet-geosearch optionally depends on @googlemaps/js-api-loader which
// dynamically injects <script> tags — forbidden under Chrome Extension MV3 CSP.
// Replace it with an empty module so webpack never bundles it.
new webpack.NormalModuleReplacementPlugin(
/@googlemaps\/js-api-loader/,
path.resolve(__dirname, 'src/lib/noop.js')
),
new DotenvPlugin(),
new ESLintPlugin({
extensions: ['js', 'ts'],
overrideConfigFile: path.resolve(__dirname, '.eslintrc'),
}),
new CopyPlugin({
patterns: [
{
from: 'static',
globOptions: {
ignore: ["**/.DS_Store","**/manifest.json"],
},
}
//TODO glob for myavail static
],
}),
],
};