forked from kazuki-sf/YouTube_Summary_with_ChatGPT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
92 lines (86 loc) · 1.93 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
const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'development';
}
const ENV = process.env.ENV = process.env.NODE_ENV;
const plugins = [
new webpack.DefinePlugin({
'process.env': {
ENV: JSON.stringify(ENV),
},
}),
new CopyWebpackPlugin({
patterns: [{
from: 'manifest.json',
},
{
from: 'src/images',
to: 'images',
},
{
from: 'src/css/*.css',
to({ context, absoluteFilename }) {
return 'contentscript/[name][ext]';
},
},
{
from: 'src/popup',
to: 'popup',
},
{
from: '_locales',
to: '_locales',
},
],
}),
new WriteFilePlugin(),
];
const fileExtensions = ['jpg', 'jpeg', 'png', 'gif', 'eot', 'otf', 'svg', 'ttf', 'woff', 'woff2'];
const moduleRules = [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
exclude: /node_modules/,
},
{
test: new RegExp(`.(${fileExtensions.join('|')})$`),
use: 'file-loader?name=[name].[ext]',
exclude: /node_modules/,
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
sources: false,
},
},
exclude: /node_modules/,
},
];
const config = {
target: 'web',
devtool: 'cheap-module-source-map',
mode: process.env.NODE_ENV || 'development',
entry: {
'contentscript/index': path.join(__dirname, 'src', 'contentscript', 'index.js'),
background: path.join(__dirname, 'background.js'),
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].bundle.js',
clean: true,
},
module: {
rules: moduleRules,
},
plugins,
};
if (ENV === 'development') {
config.devtool = 'cheap-module-source-map';
}
module.exports = config;