2019-11-28 23:43:04 +00:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
const ejs = require('ejs');
|
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
|
const { VueLoaderPlugin } = require('vue-loader');
|
2020-07-29 22:47:50 +02:00
|
|
|
const { version, betaRev } = require('./package.json');
|
2020-07-20 14:40:48 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
2022-05-27 13:24:51 +02:00
|
|
|
|
|
|
|
|
const loadDevConfig = () => {
|
|
|
|
|
if (fs.existsSync('./.dev.json')) {
|
|
|
|
|
return JSON.parse(fs.readFileSync('./.dev.json').toString());
|
|
|
|
|
} else {
|
|
|
|
|
return JSON.parse(fs.readFileSync('./.dev.sample.json').toString());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const devConfig = loadDevConfig();
|
2019-11-28 23:43:04 +00:00
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
|
mode: process.env.NODE_ENV,
|
|
|
|
|
context: __dirname + '/src',
|
|
|
|
|
entry: {
|
2020-07-28 12:07:45 +02:00
|
|
|
'background': './background/index.js',
|
2019-11-28 23:43:04 +00:00
|
|
|
'popup/popup': './popup/popup.js',
|
|
|
|
|
},
|
|
|
|
|
output: {
|
|
|
|
|
path: __dirname + '/dist',
|
|
|
|
|
filename: '[name].js',
|
|
|
|
|
},
|
|
|
|
|
resolve: {
|
|
|
|
|
extensions: ['.js', '.vue'],
|
|
|
|
|
},
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.vue$/,
|
2022-05-27 13:24:51 +02:00
|
|
|
use: 'vue-loader',
|
2019-11-28 23:43:04 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
exclude: /node_modules/,
|
2020-07-06 01:38:23 +02:00
|
|
|
options: {
|
|
|
|
|
presets: [
|
|
|
|
|
{'plugins': ['@babel/plugin-proposal-class-properties']
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2019-11-28 23:43:04 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.scss$/,
|
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.sass$/,
|
|
|
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader?indentedSyntax'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(png|jpg|jpeg|gif|svg|ico)$/,
|
|
|
|
|
loader: 'file-loader',
|
|
|
|
|
options: {
|
|
|
|
|
name: '[name].[ext]',
|
|
|
|
|
outputPath: '/images/',
|
|
|
|
|
emitFile: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
|
|
|
|
|
loader: 'file-loader',
|
|
|
|
|
options: {
|
|
|
|
|
name: '[name].[ext]',
|
|
|
|
|
outputPath: '/fonts/',
|
|
|
|
|
emitFile: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
global: 'window',
|
|
|
|
|
}),
|
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
|
filename: '[name].css',
|
|
|
|
|
}),
|
2022-05-27 13:24:51 +02:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
|
patterns: [
|
|
|
|
|
{ from: 'icons', to: 'icons', globOptions: { ignoreFiles: ['icon.xcf'] } },
|
|
|
|
|
{ from: 'images', to: 'images' },
|
|
|
|
|
{ from: 'content_script', to: 'content_script' },
|
|
|
|
|
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
|
|
|
|
{
|
|
|
|
|
from: 'manifest.json',
|
|
|
|
|
to: 'manifest.json',
|
|
|
|
|
transform: (content) => {
|
|
|
|
|
const jsonContent = JSON.parse(content);
|
|
|
|
|
jsonContent.version = version;
|
2019-11-28 23:43:04 +00:00
|
|
|
|
2024-03-25 21:32:48 +01:00
|
|
|
if (config.mode === 'development') {
|
2022-05-27 13:24:51 +02:00
|
|
|
jsonContent.permissions = jsonContent.permissions.concat(devConfig.permissions);
|
|
|
|
|
}
|
2019-11-28 23:43:04 +00:00
|
|
|
|
2022-05-27 13:24:51 +02:00
|
|
|
if (process.env.BETA) {
|
|
|
|
|
const geckoId = jsonContent.browser_specific_settings.gecko.id;
|
2024-04-11 23:10:47 +02:00
|
|
|
jsonContent.name = 'SimpleLogin BETA';
|
2022-05-27 13:24:51 +02:00
|
|
|
jsonContent.icons = {
|
|
|
|
|
'48': 'icons/icon_beta_48.png',
|
|
|
|
|
'128': 'icons/icon_beta_128.png'
|
|
|
|
|
};
|
|
|
|
|
jsonContent.version = version + '.' + betaRev;
|
|
|
|
|
jsonContent.browser_specific_settings.gecko.id = geckoId.replace('@', '-beta@');
|
|
|
|
|
}
|
2020-07-27 10:32:56 +02:00
|
|
|
|
2024-04-09 15:11:43 +02:00
|
|
|
if (process.env.FIREFOX) {
|
|
|
|
|
jsonContent.background = {
|
|
|
|
|
"scripts": ["background.js"]
|
2024-07-15 09:05:01 +02:00
|
|
|
};
|
2024-04-09 15:11:43 +02:00
|
|
|
} else { // CHROME
|
|
|
|
|
jsonContent.background = {
|
|
|
|
|
"service_worker": "background.js",
|
|
|
|
|
"type": "module"
|
2024-07-15 09:05:01 +02:00
|
|
|
};
|
2024-04-09 15:11:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-03 14:39:31 +02:00
|
|
|
if (process.env.LITE) {
|
|
|
|
|
// Remove "All sites" permissions
|
|
|
|
|
const PERMISSIONS_TO_REMOVE = [
|
|
|
|
|
"https://*/*",
|
|
|
|
|
"http://*/*"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const finalPermissions = [];
|
|
|
|
|
for (const perm of jsonContent.permissions) {
|
|
|
|
|
if (!PERMISSIONS_TO_REMOVE.includes(perm)) {
|
|
|
|
|
finalPermissions.push(perm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
jsonContent.permissions = finalPermissions;
|
|
|
|
|
|
|
|
|
|
// Change metadata
|
|
|
|
|
jsonContent.name = "SimpleLogin Without SL icon";
|
|
|
|
|
jsonContent.short_name = "SimpleLogin Without SL icon";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 18:18:30 +01:00
|
|
|
if (process.env.MAC) {
|
|
|
|
|
jsonContent.permissions.push("nativeMessaging");
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 13:24:51 +02:00
|
|
|
return JSON.stringify(jsonContent, null, 2);
|
|
|
|
|
},
|
2019-11-28 23:43:04 +00:00
|
|
|
},
|
2022-05-27 13:24:51 +02:00
|
|
|
]
|
|
|
|
|
}),
|
2019-11-28 23:43:04 +00:00
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-20 14:40:48 +02:00
|
|
|
if (config.mode === 'development') {
|
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
|
new webpack.DefinePlugin({
|
2020-07-27 10:32:56 +02:00
|
|
|
'devConfig': JSON.stringify(devConfig),
|
|
|
|
|
'process.env.BETA': JSON.stringify(!!process.env.BETA),
|
2020-07-20 14:40:48 +02:00
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 18:18:30 +01:00
|
|
|
if (process.env.MAC){
|
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
'process.env.MAC': JSON.stringify(!!process.env.MAC),
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 23:43:04 +00:00
|
|
|
if (config.mode === 'production') {
|
|
|
|
|
config.plugins = (config.plugins || []).concat([
|
|
|
|
|
new webpack.DefinePlugin({
|
2020-08-13 12:24:56 +02:00
|
|
|
'devConfig': 'null',
|
2019-11-28 23:43:04 +00:00
|
|
|
'process.env': {
|
2020-07-27 10:32:56 +02:00
|
|
|
'NODE_ENV': '"production"',
|
|
|
|
|
'BETA': JSON.stringify(!!process.env.BETA),
|
2019-11-28 23:43:04 +00:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function transformHtml(content) {
|
|
|
|
|
return ejs.render(content.toString(), {
|
|
|
|
|
...process.env,
|
2020-07-20 14:40:48 +02:00
|
|
|
devConfig,
|
2019-11-28 23:43:04 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 21:32:48 +01:00
|
|
|
if (config.mode === 'production') {
|
|
|
|
|
config.devtool="source-map";
|
|
|
|
|
} else {
|
|
|
|
|
config.devtool="cheap-source-map";
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 15:11:43 +02:00
|
|
|
module.exports = config;
|