-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
webpack.config.js
95 lines (85 loc) · 2.34 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
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
const path = require('path');
const packageFile = require('./package.json');
const libraryName = 'enhanced-github';
const libVersion = packageFile.version;
const license = packageFile.license;
const destination = path.resolve(__dirname, 'dist');
let deps = '';
Object.keys(packageFile.dependencies).map((key, index) => {
deps += `\n ${index + 1}. ${key} - ${packageFile.dependencies[key]}`;
});
const libraryHeaderComment = `${libraryName} - v${libVersion}\n
URL - https://github.com/softvar/ehanced-github\n
${license} License, Copyright Varun Malhotra
Dependencies used - ${deps}`;
function addPlugins(argv) {
const plugins = [];
plugins.push(
new webpack.BannerPlugin({
banner: libraryHeaderComment,
entryOnly: true
})
);
plugins.push(
new CleanWebpackPlugin({
default: [destination, path.resolve(__dirname, 'enhanced-github'), path.resolve(__dirname, 'enhanced-github.zip')]
})
);
plugins.push(
new CopyPlugin({
patterns: [
{ from: 'options.js', to: destination, },
{ from: 'popup.js', to: destination, },
{ from: '*html', to: destination, },
{ from: 'manifest.json', to: destination,},
{ from: 'icons/*.png', to: destination, },
{ from: 'src/background.js', to: destination, },
{ from: 'LICENSE', to: destination , }
]
})
);
if (argv.mode === 'production') {
plugins.push(
new ZipPlugin({
path: path.resolve(__dirname, 'dist'),
filename: path.resolve(__dirname, 'enhanced-github.zip')
})
);
}
return plugins;
}
module.exports = function(_env, argv) {
return {
entry: {
[libraryName]: './src/inject.js'
},
devtool: 'source-map',
mode: argv.mode,
output: {
path: destination,
filename: 'src/inject.js',
library: libraryName,
libraryTarget: 'global'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules|dist/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: addPlugins(argv),
watchOptions: {
poll: true,
ignored: /node_modules/
}
};
};