Files
ClearUrls/webpack.config.js
2020-11-08 23:32:31 +01:00

94 lines
2.2 KiB
JavaScript

const path = require('path')
const SizePlugin = require('size-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
devtool: 'source-map',
stats: 'errors-only',
entry: {
// target_path/target_file_name: full_source_path
'background/main': './source/background/main.ts'
},
output: {
path: path.join(__dirname, 'distribution'),
filename: '[name].js',
},
resolve: {
// Add '.ts' and '.tsx' as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.json'],
alias: {
'webextension-polyfill-ts': path.resolve(
path.join(__dirname, 'node_modules', 'webextension-polyfill-ts'),
),
},
},
module: {
rules: [
// all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json',
},
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'file-loader',
options: {
name(resourcePath, resourceQuery) {
return resourcePath.replace(/.+source[\/\\]/, '').replace(/\.s[ac]ss$/i, '.css')
},
},
},
// Compiles Sass to CSS
'sass-loader',
],
},
],
},
plugins: [
new SizePlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: '**/*',
context: 'source',
globOptions: {
ignore: ['**/*.js', '**/*.ts', '**/*.tsx', '**/*.scss'],
},
},
{
from: '_locales/**/*',
context: 'source'
},
{
from: 'img/*',
context: 'source'
},
{
from: 'scripts/*',
context: 'source'
}
],
}),
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: false,
compress: false,
output: {
beautify: true,
indent_level: 2, // eslint-disable-line camelcase
},
},
}),
],
},
}