This repository has been archived by the owner on Nov 12, 2021. It is now read-only.
forked from FakeFiller/fake-filler-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
105 lines (99 loc) · 2.71 KB
/
webpack.config.ts
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
// https://github.com/libertylocked/chrome-extension-typescript-react
import * as path from 'path';
import * as webpack from 'webpack';
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const isProd = (): boolean => {
return process.env.NODE_ENV === 'production';
};
const buildConfig: webpack.Configuration = {
mode: 'production',
cache: false,
entry: {
background_script: path.join(__dirname, 'src/background_script/index.ts'),
content_script: path.join(__dirname, 'src/content_script/index.ts'),
options: path.join(__dirname, 'src/options/index.tsx'),
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(scss)$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer(), cssnano()],
},
},
{ loader: 'sass-loader' },
],
},
{
loader: 'file-loader',
exclude: [/\.(html?)$/, /\.(ts|tsx|js|jsx)$/, /\.css$/, /\.scss$/, /\.json$/],
query: {
name: '[hash].[ext]',
outputPath: 'media/',
publicPath: 'build/',
},
},
],
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'dist/build'),
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new CopyWebpackPlugin([
{
context: 'public',
from: {
dot: false,
glob: '**/*',
},
to: path.join(__dirname, 'dist/'),
},
]),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
performance: {
hints: false,
},
};
if (isProd()) {
buildConfig.devtool = false;
buildConfig.plugins = (buildConfig.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') },
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.join(__dirname, 'dist')],
}),
]);
} else {
buildConfig.plugins = (buildConfig.plugins || []).concat([
new webpack.SourceMapDevToolPlugin({
exclude: /^vendor.*.\.js$/,
filename: '[file].map',
}),
]);
}
export default buildConfig;