forked from podStation/podStation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
76 lines (70 loc) · 2.06 KB
/
webpack.common.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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { ProvidePlugin } = require('webpack');
const JSON5 = require('json5');
const packageInformation = require('./package.json');
module.exports = {
entry: {
background: './src/background/podstation_bg.js',
feedFinder: './src/feedFinder.js',
podstation: './src/podstation.js',
popup: './src/popup.js',
},
plugins: [
new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
new HtmlWebpackPlugin({
template: 'src/podstation.html',
filename: 'podstation.html',
chunks: ['podstation'],
}),
new HtmlWebpackPlugin({
filename: 'background.html',
chunks: ['background'],
}),
new HtmlWebpackPlugin({
template: 'src/popup.html',
filename: 'popup.html',
chunks: ['popup'],
}),
new CopyWebpackPlugin({
patterns: [
{ from: './src/manifest.json', transform: copyPackageInformationToExtensionManifest },
{ from: './src/_locales', to: '_locales', transform: stripJsonComments },
{ from: './src/images', to: 'images' },
{ from: './src/ui/ng/partials', to: 'ui/ng/partials' },
],
}),
new MiniCssExtractPlugin(),
new ProvidePlugin({
qrcode: 'qrcode-generator',
}),
],
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
// https://stackoverflow.com/a/39609018/4274827
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: "url-loader"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: "file-loader"
},
],
},
}
function copyPackageInformationToExtensionManifest(content) {
const parsedManifest = JSON.parse(content.toString());
parsedManifest.version = packageInformation.version;
return JSON.stringify(parsedManifest, null, 4);
}
function stripJsonComments(content) {
const parsedManifest = JSON5.parse(content.toString());
return JSON.stringify(parsedManifest, null, 4);
}