-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
91 lines (89 loc) · 3.33 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
module.exports = (env, arg) => {
const mode = arg.mode;
return {
mode: mode === 'production' ? mode : 'development',
devtool: mode === 'development' ? 'inline-source-map' : false,
entry: {
'pop-up': './src/pop-up/modules/script.js',
background: './src/extension/modules/background.js',
'content-script': './src/extension/modules/content-script.js',
},
resolve: { extensions: ['.js'], modules: [path.resolve(__dirname, 'src'), 'node_modules'] },
optimization: {
minimize: mode === 'production',
},
plugins: [
new webpack.DefinePlugin({
// replace with your own api
TRANSLATION_API: JSON.stringify(
'http://localhost/chrome-extensions/custom-subtitles/dist/translation-api/',
),
}),
new HtmlWebpackPlugin({
template: 'src/pop-up/index.html',
filename: 'pop-up.html',
minify: mode === 'production',
inject: false,
scriptLoading: 'blocking',
}),
new CopyPlugin({
patterns: [
{
from: './src/extension/manifest.json',
},
{
from: './src/extension/css/',
to: './css/',
},
{
from: './src/pop-up/img/',
to: './img/',
},
{
from: './src/translation-api/',
to: './translation-api/',
},
{
from: './src/pop-up/css/styles.css',
to: './css/pop-up.css',
},
],
}),
new FileManagerPlugin({
events: {
onEnd: [
{
copy: [
{
source: './dist/pop-up.js',
destination: './dist/js/pop-up.js',
},
{
source: './dist/content-script.js',
destination: './dist/js/content-script.js',
},
{
source: './dist/background.js',
destination: './dist/js/background.js',
},
],
},
{
delete: ['./dist/pop-up.js', './dist/content-script.js', './dist/background.js'],
},
],
},
}),
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
};
};