2018-12-30 23:16:09 +01:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const ejs = require('ejs');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const WebpackShellPlugin = require('webpack-shell-plugin');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');
|
|
|
|
const { VueLoaderPlugin } = require('vue-loader');
|
2022-01-29 16:23:40 +01:00
|
|
|
const path = require('path');
|
2018-12-30 23:16:09 +01:00
|
|
|
|
|
|
|
const config = {
|
2023-10-21 17:41:09 +02:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
2018-12-30 23:16:09 +01:00
|
|
|
mode: process.env.NODE_ENV,
|
2020-06-18 22:12:28 +02:00
|
|
|
devtool: `${process.env.CHANNEL === 'stable' ? undefined : "inline-source-map"}`,
|
2018-12-30 23:16:09 +01:00
|
|
|
context: __dirname + '/src',
|
|
|
|
entry: {
|
2018-12-30 23:41:44 +01:00
|
|
|
'ext/uw': './ext/uw.js',
|
2023-07-10 22:00:53 +02:00
|
|
|
'uw-bg': './uw-bg.js',
|
2023-09-10 22:06:16 +02:00
|
|
|
'csui/csui-popup': './csui/csui-popup.js',
|
2022-01-07 00:50:58 +01:00
|
|
|
'csui/csui': './csui/csui.js',
|
2020-03-03 00:36:24 +01:00
|
|
|
// 'install/first-time/first-time':'./install/first-time/first-time.js',
|
2018-12-30 23:16:09 +01:00
|
|
|
},
|
|
|
|
output: {
|
2020-02-08 00:09:07 +01:00
|
|
|
path: __dirname + `/dist-${process.env.BROWSER == 'firefox' ? 'ff' : process.env.BROWSER}`,
|
2018-12-30 23:16:09 +01:00
|
|
|
filename: '[name].js',
|
|
|
|
},
|
2021-02-08 20:55:17 +01:00
|
|
|
|
|
|
|
devtool: "source-map",
|
|
|
|
|
2018-12-30 23:16:09 +01:00
|
|
|
resolve: {
|
2022-01-07 00:50:58 +01:00
|
|
|
// maybe we'll move vue stuff to TS some day, but today is not the day
|
2020-12-02 22:39:57 +01:00
|
|
|
extensions: [
|
2021-02-08 20:55:17 +01:00
|
|
|
'.ts', '.tsx',
|
2020-12-02 22:39:57 +01:00
|
|
|
'.js', '.vue'
|
|
|
|
],
|
2018-12-30 23:16:09 +01:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2021-10-22 00:30:36 +02:00
|
|
|
{
|
2021-02-08 22:45:41 +01:00
|
|
|
test: /\.ts$/,
|
2021-02-08 20:55:17 +01:00
|
|
|
loader: 'ts-loader',
|
2021-02-08 22:45:41 +01:00
|
|
|
exclude: /node_modules/
|
2021-02-08 20:55:17 +01:00
|
|
|
},
|
2018-12-30 23:16:09 +01:00
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loaders: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
2021-11-21 02:07:58 +01:00
|
|
|
test: /\.(sc|c)ss$/,
|
|
|
|
use: [
|
|
|
|
// MiniCssExtractPlugin.loader,
|
|
|
|
'vue-style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
// modules: {
|
|
|
|
// localIdentName: "[name]-[hash]"
|
|
|
|
// }
|
|
|
|
// options: {
|
|
|
|
// modules: true,
|
|
|
|
// // localIdentName: "🔶uw_[local]"
|
|
|
|
// localIdentName: "[name]-[hash]"
|
|
|
|
// // localIdentName: "uw_[local]"
|
|
|
|
// }
|
|
|
|
},
|
2022-01-29 16:23:40 +01:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true
|
|
|
|
}
|
|
|
|
}
|
2021-11-21 02:07:58 +01:00
|
|
|
],
|
2018-12-30 23:16:09 +01:00
|
|
|
},
|
2021-11-21 02:07:58 +01:00
|
|
|
// {
|
|
|
|
// test: /\.scss$/,
|
|
|
|
// use: [
|
|
|
|
// // MiniCssExtractPlugin.loader,
|
|
|
|
// 'css-loader',
|
|
|
|
// // {
|
|
|
|
// // loader: 'css-loader',
|
|
|
|
// // // options: {
|
|
|
|
// // // modules: true,
|
|
|
|
// // // localIdentName: "🔶uw_[local]"
|
|
|
|
// // // }
|
|
|
|
// // },
|
|
|
|
// 'sass-loader'
|
|
|
|
// ],
|
|
|
|
// },
|
2018-12-30 23:16:09 +01:00
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|svg|ico)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[path][name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff(2)?)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
name: '[path][name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
2020-01-28 23:11:15 +01:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: "babel-loader"
|
|
|
|
},
|
2018-12-30 23:16:09 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: '[name].css',
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([
|
2020-03-15 20:28:38 +01:00
|
|
|
{ from: 'res', to: 'res', ignore: ['css', 'css/**']},
|
2020-02-07 00:07:28 +01:00
|
|
|
{ from: 'ext', to: 'ext', ignore: ['conf/*', 'lib/**']},
|
2022-01-07 00:50:58 +01:00
|
|
|
{ from: 'csui', to: 'csui', ignore: ['src']},
|
2020-12-02 22:39:57 +01:00
|
|
|
|
2020-12-05 04:12:37 +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'},
|
|
|
|
|
2020-12-02 22:39:57 +01:00
|
|
|
// This is extension icon, as used on extension lists and/or extension's action button
|
2021-10-22 00:30:36 +02:00
|
|
|
// This folder does not contain any GUI icons — these are in /res/icons.
|
2020-12-02 22:39:57 +01:00
|
|
|
// (TODO: check if this copy is even necessary — /icons has same content as /res/icons)
|
2018-12-30 23:16:09 +01:00
|
|
|
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
|
2023-09-10 22:06:16 +02:00
|
|
|
{ from: 'csui/csui-popup.html', to: 'csui/csui-popup.html', transform: transformHtml },
|
2024-06-05 01:08:50 +02:00
|
|
|
{ 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 },
|
2020-03-15 20:28:38 +01:00
|
|
|
// { from: 'install/first-time/first-time.html', to: 'install/first-time/first-time.html', transform: transformHtml},
|
2018-12-30 23:16:09 +01:00
|
|
|
{
|
|
|
|
from: 'manifest.json',
|
|
|
|
to: 'manifest.json',
|
|
|
|
transform: (content) => {
|
|
|
|
const jsonContent = JSON.parse(content);
|
2019-05-04 17:05:08 +02:00
|
|
|
// jsonContent.version = version;
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2023-07-10 22:00:53 +02:00
|
|
|
// if (config.mode === 'development') {
|
|
|
|
// jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
|
|
|
|
// }
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2019-11-28 23:37:26 +01:00
|
|
|
if (process.env.CHANNEL === 'nightly') {
|
|
|
|
jsonContent.name = "Ultrawidify - nightly";
|
2019-11-29 00:12:31 +01:00
|
|
|
jsonContent.description = "FOR TESTING ONLY -- THIS BUILD USES ONLY THE FRESHEST COMMITS FROM GITHUB AND MAY THEREFORE BE COMPLETELY BROKEN";
|
2019-11-28 23:37:26 +01:00
|
|
|
|
|
|
|
// 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
|
2021-01-30 12:21:04 +01:00
|
|
|
}.${process.env.BUILD_NUMBER === undefined ? 0 : process.env.BUILD_NUMBER}`;
|
2019-11-28 23:37:26 +01:00
|
|
|
jsonContent.browser_action.default_title = "Ultrawidify Nightly";
|
2021-10-22 00:30:36 +02:00
|
|
|
|
2019-12-03 02:11:16 +01:00
|
|
|
// because we don't want web-ext to submit this as proper release
|
2019-12-03 02:01:29 +01:00
|
|
|
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
|
2021-01-30 12:21:04 +01:00
|
|
|
}.${process.env.BUILD_NUMBER === undefined ? 0 : process.env.BUILD_NUMBER}`;
|
2019-12-03 02:01:29 +01:00
|
|
|
jsonContent.browser_action.default_title = "Ultrawidify Testing";
|
2021-10-22 00:30:36 +02:00
|
|
|
|
2019-12-03 02:11:16 +01:00
|
|
|
// because we don't want web-ext to submit this as proper release
|
2019-11-29 00:31:20 +01:00
|
|
|
delete jsonContent.applications;
|
2019-11-28 23:37:26 +01:00
|
|
|
}
|
|
|
|
|
2019-05-09 21:10:45 +02:00
|
|
|
if (process.env.BROWSER !== 'firefox') {
|
|
|
|
jsonContent.version = jsonContent.version.replace(/[a-zA-Z-]/g, '');
|
2023-10-21 17:41:09 +02:00
|
|
|
try {
|
|
|
|
delete jsonContent.options_ui.browser_style;
|
|
|
|
} catch (e) { }
|
|
|
|
try {
|
|
|
|
delete jsonContent.background.scripts;
|
|
|
|
} catch (e) {}
|
2023-07-10 22:00:53 +02:00
|
|
|
} else {
|
|
|
|
delete jsonContent.background.service_worker;
|
2019-05-09 21:10:45 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 23:16:09 +01:00
|
|
|
return JSON.stringify(jsonContent, null, 2);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]),
|
|
|
|
new WebpackShellPlugin({
|
|
|
|
onBuildEnd: ['node scripts/remove-evals.js'],
|
|
|
|
}),
|
2019-05-09 21:10:45 +02:00
|
|
|
new webpack.DefinePlugin({
|
2020-01-27 23:35:38 +01:00
|
|
|
'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,
|
2024-12-22 23:16:54 +01:00
|
|
|
'__VUE_PROD_DEVTOOLS__': false,
|
|
|
|
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': true
|
2019-05-09 21:10:45 +02:00
|
|
|
})
|
2018-12-30 23:16:09 +01:00
|
|
|
],
|
2020-02-14 20:55:20 +01:00
|
|
|
optimization: {
|
2020-06-18 22:12:28 +02:00
|
|
|
// minimize: false,
|
|
|
|
// occurrenceOrder: false,
|
|
|
|
// providedExports: false,
|
|
|
|
// usedExports: false,
|
|
|
|
// concatenateModules: false,
|
|
|
|
// sideEffects: false,
|
2020-02-14 20:55:20 +01:00
|
|
|
}
|
2018-12-30 23:16:09 +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
|
|
|
|
2018-12-30 23:16:09 +01:00
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: '"production"',
|
|
|
|
},
|
2019-05-09 21:10:45 +02:00
|
|
|
})
|
2018-12-30 23:16:09 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.HMR === 'true') {
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
new ChromeExtensionReloader(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function transformHtml(content) {
|
|
|
|
return ejs.render(content.toString(), {
|
|
|
|
...process.env,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config;
|