-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (84 loc) · 2.37 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
function geneEntry(arr, pathBase) {
const path = require('path');
const fs = require('fs');
let reduce = arr.reduce((result, item) => {
let {type, name} = item;
if (String(type).includes('file')) {
let filename = `${name}.js`;
result[filename] = path.join(pathBase, filename);
}
if (String(type).includes('dir')) {
let strings = fs.readdirSync(path.join(pathBase, name));
strings
.filter(value => value.endsWith('.js'))
.forEach((filename) => {
let key_ = `${name}/${filename}`;
result[key_] = path.join(pathBase, name, filename);
});
}
return result;
}, {});
console.log(`meslog reduce=\n`, reduce);
return reduce;
}
/**
*
* @param arr{Array} src file/dir arr
* @param src{String} src path
* @param dest{String} dest path
* @return Array
*/
function geneCopyPatterns(arr, src, dest) {
const path = require('path');
const fs = require('fs');
return arr.reduce((result, value) => {
let a = path.join(src, value);
let b = path.join(dest, value);
let obj = {from: a, to: b};
result.push(obj);
return result;
}, Array.from([]));
}
//=============================================================================
const path = require('path');
const fs = require('fs');
const CopyPlugin = require('copy-webpack-plugin');
let pathDirSrc = path.join(__dirname, 'src','addons');
let pathDirDist = path.join(__dirname, 'dist');
let arr = [
{type: 'file', name: 'background'},
{type: 'dir', name: 'option'},
{type: 'dir', name: 'js'},
];
let entry = geneEntry(arr, pathDirSrc);
const patterns = geneCopyPatterns(
[
'_locales', //
'icons', // icon
'option/options.html', // options_ui
'background.html', //
'LICENSE', //
'manifest.json', //
],
pathDirSrc,
pathDirDist,
);
//************************************************************************
//************************************************************************
//************************************************************************
//************************************************************************
// entry only support js file
module.exports = {
mode: 'production', // production
entry: entry,
output: {
path: pathDirDist,
filename: '[name]',
},
experiments: {
topLevelAwait: true,
},
plugins: [
new CopyPlugin({patterns: patterns}),
],
};