/
webpack.config.js
104 lines (98 loc) · 2.49 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
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');
const entryPoints = {
main: [path.resolve(__dirname, 'src', 'content', 'index.ts')],
background: path.resolve(__dirname, 'src', 'background', 'background.ts'),
styling: path.resolve(__dirname, 'src', 'styles', '_main.scss'),
popup: path.resolve(__dirname, 'src', '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', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(jpg|jpeg|png|gif|woff|woff2|eot|ttf|svg)$/i,
use: 'url-loader?limit=1024',
},
{
test: /\.(s[ac]ss|css)$/i,
use: [
// 'style-loader', // Injects CSS into the DOM
MiniCssExtractPlugin.loader,
'css-loader', // Translates CSS into CommonJS
{
loader: 'postcss-loader', // postcss loader needed for tailwindcss
options: {
postcssOptions: {
ident: 'postcss',
plugins: [tailwindcss, autoprefixer],
},
},
},
'sass-loader', // Compiles Sass to CSS,
],
},
],
},
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')];