-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
120 lines (116 loc) · 2.74 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
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
112
113
114
115
116
117
118
119
120
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const DIST_DIR = path.resolve(__dirname, 'dist');
const SRC_DIR = path.resolve(__dirname, 'src');
module.exports = {
output: {
filename: '[name].js',
path: DIST_DIR,
},
entry: {
sidebar: './src/sidebar/index.jsx',
background: './src/background/index.js',
},
resolve: {
modules: [SRC_DIR, 'node_modules'],
extensions: ['.js', '.jsx', '.json'],
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
},
},
module: {
rules: [
// CSS for node_modules
{
include: /node_modules/,
test: /\.css$/i,
use: [
'cache-loader',
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: false,
},
},
],
},
{
test: /\.s[ac]ss$/i, // SCSS
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
import: true,
modules: {
mode: 'local',
localIdentName: '[local]__[hash:base64:5]',
},
},
},
'cache-loader',
{
loader: 'sass-loader',
options: {
sourceMap: false,
},
},
],
},
{
test: /\.(woff(2)?|ttf|eot|svg|png)$/, // FONTS
use: [
{
loader: 'cache-loader',
},
{
loader: 'file-loader',
options: {
name: '[hash].[ext]',
outputPath: 'fonts/',
},
},
],
},
{
test: /\.jsx?$/, // TYPESCRIPT
use: [
{
loader: 'cache-loader',
},
{
loader: 'babel-loader',
},
],
exclude: /node_modules/,
},
{
test: require.resolve('webextension-polyfill'),
use: 'imports-loader?browser=>undefined',
},
],
},
plugins: [
new webpack.ProvidePlugin({
browser: 'webextension-polyfill',
}),
new CopyPlugin([
{ from: 'src/assets', to: '.' },
{ from: 'src/manifest.json', to: '.' },
]),
new HtmlWebpackPlugin({
chunks: ['sidebar'],
template: 'src/sidebar/template.html',
filename: 'sidebar.html',
}),
new MiniCssExtractPlugin(),
],
};