You've already forked hotpocket
BTHLABS-50: Safari Web extension
Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl> Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
125
services/extension/rollup.config.js
Normal file
125
services/extension/rollup.config.js
Normal file
@@ -0,0 +1,125 @@
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import copy from 'rollup-plugin-copy';
|
||||
import {string} from 'rollup-plugin-string';
|
||||
|
||||
import packageJSON from './package.json' with {type: 'json'};
|
||||
import manifestCommon from './src/manifest/common.json' with {type: 'json'};
|
||||
import manifestSafari from './src/manifest/safari.json' with {type: 'json'};
|
||||
|
||||
const BANNER = `/*!
|
||||
* HotPocket by BTHLabs (https://hotpocket.app/)
|
||||
* Copyright 2025-present BTHLabs <contact@bthlabs.pl> (https://bthlabs.pl/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/`;
|
||||
|
||||
const ENV = process.env['NODE_ENV'] || 'development';
|
||||
const IS_PRODUCTION = (ENV === 'production');
|
||||
const TARGET = process.env['HOTPOCKET_EXTENSION_TARGET'] || 'safari';
|
||||
|
||||
let BASE_URL = process.env['HOTPOCKET_EXTENSION_RPC_BASE_URL'] || null;
|
||||
if (BASE_URL === null) {
|
||||
if (IS_PRODUCTION) {
|
||||
BASE_URL = 'https://my.hotpocket.app/';
|
||||
} else {
|
||||
BASE_URL = 'https://app.hotpocket.work.bthlabs.net/';
|
||||
}
|
||||
}
|
||||
|
||||
const PLUGINS = [
|
||||
string({
|
||||
include: /\.html$/,
|
||||
}),
|
||||
replace({
|
||||
include: /\.js$/,
|
||||
preventAssignment: true,
|
||||
values: {
|
||||
'__HOTPOCKET_EXTENSION_ENV__': JSON.stringify(ENV),
|
||||
'__HOTPOCKET_EXTENSION_VERSION__': JSON.stringify(packageJSON.version),
|
||||
'__HOTPOCKET_EXTENSION_BASE_URL__': JSON.stringify(BASE_URL),
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const manifestJsonOutputPlugin = () => {
|
||||
return {
|
||||
name: 'manifest-json',
|
||||
renderChunk: async (code, chunk, outputOptions) => {
|
||||
let result = {...manifestCommon};
|
||||
|
||||
if (TARGET === 'safari') {
|
||||
result = {
|
||||
...result,
|
||||
...manifestSafari,
|
||||
};
|
||||
}
|
||||
|
||||
result.version = packageJSON.version;
|
||||
|
||||
return JSON.stringify(result, null, 2);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
let OUTPUT_PATH = `dist/${TARGET}`;
|
||||
if (TARGET === 'safari') {
|
||||
OUTPUT_PATH = '../apple/Shared (Extension)/Resources';
|
||||
}
|
||||
|
||||
export default [
|
||||
{
|
||||
input: `src/content/${TARGET}.js`,
|
||||
output: {
|
||||
file: `${OUTPUT_PATH}/content-bundle.js`,
|
||||
format: 'iife',
|
||||
banner: BANNER,
|
||||
sourcemap: false,
|
||||
},
|
||||
plugins: [
|
||||
...PLUGINS,
|
||||
copy({
|
||||
targets: [
|
||||
{
|
||||
src: 'assets/_locales',
|
||||
dest: OUTPUT_PATH,
|
||||
},
|
||||
{
|
||||
src: 'assets/images',
|
||||
dest: OUTPUT_PATH,
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
input: `src/background/${TARGET}.js`,
|
||||
output: {
|
||||
file: `${OUTPUT_PATH}/background-bundle.js`,
|
||||
format: 'iife',
|
||||
banner: BANNER,
|
||||
sourcemap: false,
|
||||
},
|
||||
plugins: PLUGINS,
|
||||
},
|
||||
{
|
||||
input: `src/manifest.js`,
|
||||
output: {
|
||||
file: `${OUTPUT_PATH}/manifest.json`,
|
||||
format: 'es',
|
||||
sourcemap: false,
|
||||
plugins: [
|
||||
manifestJsonOutputPlugin(),
|
||||
],
|
||||
},
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user