mirror of
https://github.com/abhijithvijayan/web-extension-starter.git
synced 2025-10-07 07:22:37 +02:00
129 lines
4.0 KiB
JavaScript
129 lines
4.0 KiB
JavaScript
const path = require('path');
|
|
const webpack = require('webpack');
|
|
const wextManifest = require('wext-manifest');
|
|
const ZipPlugin = require('zip-webpack-plugin');
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const WriteWebpackPlugin = require('write-webpack-plugin');
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
|
|
|
|
const manifestInput = require('./src/manifest');
|
|
|
|
const targetBrowser = process.env.TARGET_BROWSER;
|
|
const manifest = wextManifest[targetBrowser](manifestInput);
|
|
|
|
module.exports = {
|
|
mode: 'development',
|
|
|
|
entry: {
|
|
background: './src/scripts/background.js',
|
|
popup: './src/scripts/popup.js',
|
|
options: './src/scripts/options.js',
|
|
styles: ['./src/styles/popup.scss', './src/styles/options.scss'],
|
|
},
|
|
|
|
output: {
|
|
filename: 'js/[name].bundle.js',
|
|
path: path.resolve(__dirname, 'extension', targetBrowser),
|
|
},
|
|
|
|
plugins: [
|
|
new webpack.ProgressPlugin(),
|
|
new FixStyleOnlyEntriesPlugin({ silent: true }),
|
|
new CleanWebpackPlugin({
|
|
cleanOnceBeforeBuildPatterns: [
|
|
path.join(process.cwd(), `extension/${targetBrowser}`),
|
|
path.join(process.cwd(), `extension/${targetBrowser}.zip`),
|
|
],
|
|
cleanStaleWebpackAssets: false,
|
|
verbose: true,
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
template: 'src/options.html',
|
|
// inject: false,
|
|
chunks: ['options'],
|
|
filename: 'options.html',
|
|
}),
|
|
new HtmlWebpackPlugin({
|
|
template: 'src/popup.html',
|
|
// inject: false,
|
|
chunks: ['popup'],
|
|
filename: 'popup.html',
|
|
}),
|
|
new CopyWebpackPlugin([{ from: 'src/assets', to: 'assets' }]),
|
|
new WriteWebpackPlugin([{ name: manifest.name, data: Buffer.from(manifest.content) }]),
|
|
],
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /.(js|jsx)$/,
|
|
include: [path.resolve(__dirname, 'src/scripts')],
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
plugins: ['syntax-dynamic-import'],
|
|
|
|
presets: [
|
|
[
|
|
'@babel/preset-env',
|
|
{
|
|
modules: false,
|
|
},
|
|
],
|
|
],
|
|
},
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
{
|
|
loader: 'file-loader',
|
|
options: {
|
|
name: '[name].css',
|
|
context: './src/styles/',
|
|
outputPath: 'css/',
|
|
},
|
|
},
|
|
'extract-loader',
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
},
|
|
},
|
|
{
|
|
loader: 'postcss-loader',
|
|
options: {
|
|
ident: 'postcss',
|
|
// eslint-disable-next-line global-require
|
|
plugins: [require('autoprefixer')()],
|
|
},
|
|
},
|
|
'resolve-url-loader',
|
|
'sass-loader',
|
|
],
|
|
},
|
|
],
|
|
},
|
|
|
|
optimization: {
|
|
minimizer: [
|
|
new TerserPlugin({
|
|
cache: true,
|
|
parallel: true,
|
|
}),
|
|
new ZipPlugin({
|
|
path: path.resolve(__dirname, 'extension'),
|
|
filename: `${targetBrowser}.zip`,
|
|
}),
|
|
],
|
|
},
|
|
|
|
devServer: {
|
|
contentBase: path.join(__dirname, 'extension'),
|
|
},
|
|
};
|