2fas-browser-extension/webpack/production/background.prod.config.js
2023-03-21 08:20:34 +01:00

95 lines
2.5 KiB
JavaScript

//
// This file is part of the 2FAS Browser Extension (https://github.com/twofas/2fas-browser-extension)
// Copyright © 2023 Two Factor Authentication Service, Inc.
// Contributed by Grzegorz Zając. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
//
// UTILS
const DotenvConfig = require('../utils/dotenvConfig');
// PACKAGES
const webpack = require('webpack');
const path = require('path');
const ESLintPlugin = require('eslint-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const backgroundProdConfig = {
name: 'background',
entry: './src/background/background.js',
mode: 'production',
devtool: 'cheap-module-source-map',
target: 'web',
node: false,
output: {
path: path.join(__dirname, '../../public/background'),
filename: 'background.js'
},
module: {
rules: [
{
test: /.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
babelrc: true,
cacheDirectory: false
}
}
]
},
{
test: /images.*\.(svg)$/i,
use: [{ loader: 'svg-inline-loader' }]
}
]
},
externals: {
crypto: 'crypto',
constants: 'constants'
},
optimization: {
moduleIds: 'named',
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin()
]
},
resolve: {
modules: ['node_modules']
},
plugins: [
new ESLintPlugin({
formatter: require('eslint-friendly-formatter'),
emitError: true,
emitWarning: true,
failOnWarning: false,
failOnError: false
}),
new webpack.ProvidePlugin({
global: require.resolve('../utils/global.js')
}),
DotenvConfig
]
};
module.exports = backgroundProdConfig;