build: add webpack build support for Safari

This commit is contained in:
EnixCoda 2022-01-14 16:53:44 +08:00
parent 7ab1c95b99
commit c9c968aa2c
2 changed files with 21 additions and 2 deletions

View file

@ -8,7 +8,8 @@
"private": true,
"homepage": "https://github.com/EnixCoda/Gitako",
"scripts": {
"start": "VERSION=dev-v$(node scripts/get-version.js) webpack --watch",
"dev": "VERSION=dev-v$(node scripts/get-version.js) webpack --watch",
"dev-safari": "TARGET=safari yarn run dev",
"debug-firefox": "web-ext run -s dist",
"analyse-bundle": "ANALYSE= NODE_ENV=production webpack",
"postinstall": "rm -rf node_modules/@types/react-native && node scripts/fix-pjax-api",

View file

@ -9,6 +9,17 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
const srcPath = path.resolve(__dirname, 'src')
const packagesPath = path.resolve(__dirname, 'packages')
function resolvePathInput(input) {
return path.isAbsolute(input) ? input : path.resolve(process.cwd(), input)
}
const buildTarget = process.env.TARGET
const buildTargetOutputMap = {
safari: 'Safari/Gitako/Gitako Extension/Resources',
}
const envOutputDir = process.env.OUTPUT_DIR || buildTargetOutputMap[buildTarget]
const outputPath = envOutputDir ? resolvePathInput(envOutputDir) : path.resolve(__dirname, 'dist')
const IN_PRODUCTION_MODE = process.env.NODE_ENV === 'production'
const plugins = [
new CopyWebpackPlugin([
@ -24,6 +35,13 @@ const plugins = [
author,
homepage_url,
})
// Disable custom domains for Safari
if (buildTarget === 'safari') {
Reflect.deleteProperty(manifest, 'optional_permissions')
Reflect.deleteProperty(manifest, 'background')
}
if (!IN_PRODUCTION_MODE) {
Object.assign(manifest, {
web_accessible_resources: manifest.web_accessible_resources.concat('*.map'), // enable source mapping while developing
@ -75,7 +93,7 @@ module.exports = {
devtool: IN_PRODUCTION_MODE ? 'source-map' : 'inline-source-map',
mode: IN_PRODUCTION_MODE ? 'production' : 'development',
output: {
path: path.resolve(__dirname, 'dist'),
path: outputPath,
filename: '[name].js',
},
resolve: {