Skip to content

Commit

Permalink
updated webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
AmolSoans committed Dec 8, 2024
1 parent 8d96aa3 commit ad5b60e
Showing 1 changed file with 52 additions and 39 deletions.
91 changes: 52 additions & 39 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
Expand All @@ -7,8 +6,56 @@ const Dotenv = require('dotenv-webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');

// Check if we're in web development mode
const isWebMode = process.env.NODE_ENV === 'development' && process.env.TARGET !== 'extension';

// Separate development-only plugins
const developmentPlugins = isWebMode ? [] : [
new ExtReloader({
port: 9090,
reloadPage: true,
entries: {
background: 'background',
extensionPage: ['popup']
}
})
];

// Core plugins needed for both production and development
const commonPlugins = [
new Dotenv(),
new HtmlWebpackPlugin({
template: './public/popup/index.html',
filename: 'popup.html',
chunks: ['popup']
}),
new MiniCssExtractPlugin({
filename: '[name].css'
})
];

// Extension-specific plugins needed for both production and development
const extensionPlugins = !isWebMode ? [
new CopyWebpackPlugin({
patterns: [
{
from: 'manifest.json',
to: 'manifest.json',
transform(content) {
return Buffer.from(JSON.stringify({
...JSON.parse(content.toString()),
version: process.env.npm_package_version
}))
}
},
{
from: 'src/assets',
to: 'assets'
}
]
})
] : [];

module.exports = {
mode: process.env.NODE_ENV || 'development',
entry: isWebMode ? {
Expand Down Expand Up @@ -62,45 +109,11 @@ module.exports = {
}
},
plugins: [
new Dotenv(),
new HtmlWebpackPlugin({
template: './public/popup/index.html',
filename: 'popup.html',
chunks: ['popup']
}),
...(!isWebMode ? [
new CopyWebpackPlugin({
patterns: [
{
from: 'manifest.json',
to: 'manifest.json',
transform(content) {
return Buffer.from(JSON.stringify({
...JSON.parse(content.toString()),
version: process.env.npm_package_version
}))
}
},
{
from: 'src/assets',
to: 'assets'
}
]
}),
new ExtReloader({
port: 9090,
reloadPage: true,
entries: {
background: 'background',
extensionPage: ['popup']
}
})
] : []),
new MiniCssExtractPlugin({
filename: '[name].css'
})
...commonPlugins,
...extensionPlugins,
...developmentPlugins
],
devtool: 'cheap-module-source-map',
devtool: process.env.NODE_ENV === 'production' ? false : 'cheap-module-source-map',
devServer: isWebMode ? {
hot: true,
historyApiFallback: true,
Expand Down

0 comments on commit ad5b60e

Please sign in to comment.