ultrawidify/webpack.config.js

248 lines
8.8 KiB
JavaScript
Raw Normal View History

const webpack = require('webpack');
const ejs = require('ejs');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2025-12-01 01:03:12 +01:00
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const path = require('path');
2025-12-15 19:42:07 +01:00
const aliases = require('./paths.config');
const config = {
2023-10-21 17:41:09 +02:00
watchOptions: {
ignored: /node_modules/
},
mode: process.env.NODE_ENV,
devtool: `${process.env.CHANNEL === 'stable' ? undefined : "inline-source-map"}`,
context: __dirname + '/src',
entry: {
'ext/uw': './ext/uw.js',
2023-07-10 22:00:53 +02:00
'uw-bg': './uw-bg.js',
'csui/csui-popup': './csui/csui-popup.js',
2025-12-01 01:03:12 +01:00
// 'csui/settings': './csui/settings.js',
// 'csui/csui': './csui/csui.js',
// 'ui/pages/updated/updated': './ui/pages/updated/updated.js',
'ui/pages/updated/updated': './ui/pages/updated/updated.js',
'ui/pages/settings/settings': './ui/pages/settings/settings.js',
},
output: {
2020-02-08 00:09:07 +01:00
path: __dirname + `/dist-${process.env.BROWSER == 'firefox' ? 'ff' : process.env.BROWSER}`,
filename: '[name].js',
},
2021-02-08 20:55:17 +01:00
devtool: "source-map",
resolve: {
2025-12-15 19:42:07 +01:00
alias: aliases, // SEE: paths.conf.js
// maybe we'll move vue stuff to TS some day, but today is not the day
extensions: [
2021-02-08 20:55:17 +01:00
'.ts', '.tsx',
'.js', '.vue'
],
},
module: {
rules: [
2021-10-22 00:30:36 +02:00
{
2021-02-08 22:45:41 +01:00
test: /\.ts$/,
2025-12-01 01:03:12 +01:00
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
}
}
],
2021-02-08 20:55:17 +01:00
},
{
test: /\.vue$/,
2025-12-01 01:03:12 +01:00
use: [
{
loader: 'vue-loader'
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
2025-12-01 01:03:12 +01:00
use: [
{
loader: 'babel-loader'
}
]
},
{
test: /\.(sc|c|postc)ss$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
2025-12-01 01:03:12 +01:00
options: {
// Uncomment if you want CSS modules
// modules: {
// localIdentName: "[name]-[hash]"
// }
}
},
'postcss-loader',
2025-12-01 01:03:12 +01:00
]
},
{
2025-12-01 01:03:12 +01:00
test: /\.(png|jpg|webp|gif|svg|ico)$/,
type: 'asset/resource',
generator: {
filename: '[path][name][ext]' // Webpack 5 uses generator.filename
}
},
{
test: /\.(woff(2)?)$/,
2025-12-01 01:03:12 +01:00
type: 'asset/resource',
generator: {
filename: '[path][name][ext]'
}
}
]
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
2025-12-01 01:03:12 +01:00
new CopyWebpackPlugin({
patterns: [
{ from: 'res', to: 'res', globOptions: { ignore: ['css', 'css/**'] } },
{ from: 'ext', to: 'ext', globOptions: { ignore: ['conf/*', 'lib/**'] } },
{ from: 'csui', to: 'csui', globOptions: { ignore: ['src'] }},
{ from: 'ui/res', to: 'ui/res' },
2019-11-28 23:37:26 +01:00
2025-12-01 01:03:12 +01:00
// we need to get webextension-polyfill and put it in common/lib
{ from: '../node_modules/webextension-polyfill/dist/browser-polyfill.js', to: 'common/lib/browser-polyfill.js'},
2019-05-09 21:10:45 +02:00
2025-12-01 01:03:12 +01:00
// This is extension icon, as used on extension lists and/or extension's action button
// This folder does not contain any GUI icons — these are in /res/icons.
// (TODO: check if this copy is even necessary — /icons has same content as /res/icons)
{ from: 'icons', to: 'icons', globOptions: { ignore: ['icon.xcf'] } },
{ from: 'csui/csui-popup.html', to: 'csui/csui-popup.html', transform: transformHtml },
{ from: 'csui/csui-overlay-normal.html', to: 'csui/csui.html', transform: transformHtml },
{ from: 'csui/csui-overlay-dark.html', to: 'csui/csui-dark.html', transform: transformHtml },
{ from: 'csui/csui-overlay-light.html', to: 'csui/csui-light.html', transform: transformHtml },
{ from: 'ui/pages/settings/index.html', to: 'ui/pages/settings/index.html', transform: transformHtml },
// { from: 'ui/pages/installed/index.html', to: 'ui/pages/installed/index.html', transform: transformHtml },
{ from: 'ui/pages/updated/index.html', to: 'ui/pages/updated/index.html', transform: transformHtml },
{ from: 'ui/pages/settings/index.html', to: 'ui/pages/settings/index.html', transform: transformHtml },
{
from: 'manifest.json',
to: 'manifest.json',
transform: (content) => {
const jsonContent = JSON.parse(content);
// jsonContent.version = version;
// if (config.mode === 'development') {
// jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
// }
if (process.env.CHANNEL === 'nightly') {
jsonContent.name = "Ultrawidify - nightly";
jsonContent.description = "FOR TESTING ONLY -- THIS BUILD USES ONLY THE FRESHEST COMMITS FROM GITHUB AND MAY THEREFORE BE COMPLETELY BROKEN";
// version numbers for nightly builds: YYMM.DD.BUILD_NUMBER
jsonContent.version = `${new Date()
.toISOString() // YYYY-MM-DDTHH:MM:SS...
.split('T')[0] // gives YYYY-MM-DD
.substr(2) // YYYY -> YY
.replace('-', '') // YY-MM-DD -> YYMM-DD
.replace('-', '.') // YYMM-DD -> YYMM.DD
}.${process.env.BUILD_NUMBER === undefined ? 0 : process.env.BUILD_NUMBER}`;
jsonContent.browser_action.default_title = "Ultrawidify Nightly";
// because we don't want web-ext to submit this as proper release
delete jsonContent.applications;
} else if (process.env.CHANNEL === 'testing') {
jsonContent.name = "Ultrawidify - testing";
jsonContent.description = "FOR TESTING ONLY -- this build is intended for testing a fix of certain bugs. It's not fit for normal use.";
// version numbers for nightly builds: YYMM.DD.BUILD_NUMBER
jsonContent.version = `${new Date()
.toISOString() // YYYY-MM-DDTHH:MM:SS...
.split('T')[0] // gives YYYY-MM-DD
.substr(2) // YYYY -> YY
.replace('-', '') // YY-MM-DD -> YYMM-DD
.replace('-', '.') // YYMM-DD -> YYMM.DD
}.${process.env.BUILD_NUMBER === undefined ? 0 : process.env.BUILD_NUMBER}`;
jsonContent.browser_action.default_title = "Ultrawidify Testing";
// because we don't want web-ext to submit this as proper release
delete jsonContent.applications;
}
if (process.env.BROWSER !== 'firefox') {
jsonContent.version = jsonContent.version.replace(/[a-zA-Z-]/g, '');
try {
delete jsonContent.options_ui.browser_style;
} catch (e) { }
try {
delete jsonContent.background.scripts;
} catch (e) {}
} else {
delete jsonContent.background.service_worker;
}
return JSON.stringify(jsonContent, null, 2);
},
},
2025-12-01 01:03:12 +01:00
]
}),
new WebpackShellPluginNext({
onBuildEnd: {
scripts: ['node scripts/remove-evals.js'],
blocking: true,
parallel: false,
},
}),
2019-05-09 21:10:45 +02:00
new webpack.DefinePlugin({
'process.env.BROWSER': JSON.stringify(process.env.BROWSER),
2021-06-13 02:19:05 +02:00
'process.env.CHANNEL': JSON.stringify(process.env.CHANNEL),
'__VUE_OPTIONS_API__': true,
'__VUE_PROD_DEVTOOLS__': false,
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': true
2019-05-09 21:10:45 +02:00
})
],
2020-02-14 20:55:20 +01:00
optimization: {
// minimize: false,
// occurrenceOrder: false,
// providedExports: false,
// usedExports: false,
// concatenateModules: false,
// sideEffects: false,
2020-02-14 20:55:20 +01:00
}
};
if (config.mode === 'production') {
config.plugins = (config.plugins || []).concat([
new webpack.DefinePlugin({
2021-06-13 02:19:05 +02:00
'__VUE_OPTIONS_API__': true,
'__VUE_PROD_DEVTOOLS__': false,
2021-10-22 00:30:36 +02:00
'process.env': {
NODE_ENV: '"production"',
},
2019-05-09 21:10:45 +02:00
})
]);
}
if (process.env.HMR === 'true') {
config.plugins = (config.plugins || []).concat([
2025-12-01 01:03:12 +01:00
// new ChromeExtensionReloader(), // no longer a thing for webpack 5
]);
}
function transformHtml(content) {
return ejs.render(content.toString(), {
...process.env,
});
}
module.exports = config;