-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
111 lines (106 loc) · 2.39 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const tailwindcss = require('tailwindcss');
const autoprefixer = require('autoprefixer');
const fs = require('fs');
const path = require('path');
const output = 'dist';
const json = require('./manifest.json');
// Entry points
const entryPoints = {
main: [path.resolve(__dirname, 'src', 'app', 'content', 'content.ts')],
background: path.resolve(
__dirname,
'src',
'app',
'background',
'background.ts',
),
styling: path.resolve(__dirname, 'src', 'app', 'main.css'),
popup: path.resolve(__dirname, 'src', 'app', 'popup', 'popup.tsx'),
};
function fillConfig(version) {
return {
entry: entryPoints,
devtool: 'cheap-module-source-map',
output: {
path: path.join(__dirname, output, version),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(jpg|jpeg|png|gif|woff|woff2|eot|ttf|svg)$/i,
use: 'url-loader?limit=1024',
},
{
test: /\.(css)$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
plugins: [tailwindcss, autoprefixer],
},
},
},
],
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: '.', to: '.', context: 'public' },
{
from: '.',
to: './',
context: `public`,
},
],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new HtmlPlugin({
title: 'Mafia Engine',
filename: 'popup.html',
chunks: ['popup'],
}),
{
apply(compiler) {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
const commonFields = json['commonFields'];
const versionFields = json[version];
const compiledManifest = {
...commonFields,
...versionFields,
};
fs.writeFileSync(
`./${output}/${version}/manifest.json`,
JSON.stringify(compiledManifest, null, 2),
);
});
},
},
],
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};
}
module.exports = [fillConfig('v2'), fillConfig('v3')];