diff --git a/.gitignore b/.gitignore index 0a6570e4..3502651d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /.idea +/.parcel-cache /coverage /dist /node_modules +/build *.nupkg diff --git a/package.json b/package.json index 3ec9c9be..23e3e261 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,15 @@ "electronim": "bin.js" }, "scripts": { - "pretest": "eslint --ignore-path .gitignore .", - "start": "electron .", + "pretest": "eslint --ignore-path .gitignore . && node parcel.js", "test": "jest --coverage", + "prestart": "node parcel.js", + "start": "electron .", + "prebuild:linux": "", "build:linux": "electron-builder --linux", + "prebuild:mac": "node parcel.js", "build:mac": "electron-builder --mac", + "prebuild:win": "node parcel.js", "build:win": "electron-builder --win" }, "publishConfig": { diff --git a/parcel.js b/parcel.js new file mode 100755 index 00000000..794493a1 --- /dev/null +++ b/parcel.js @@ -0,0 +1,82 @@ +#!/usr/bin/env node +/* + Copyright 2022 Marc Nuri San Felix + + 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. + */ +/* eslint-disable no-console */ +const {Parcel} = require('@parcel/core'); +const fsp = require('fs/promises'); +const fs = require('fs'); +const path = require('path'); +const BUILD_DIR = 'build'; +const BUNDLES_DIR = 'bundles'; +const CACHE_DIR = '.parcel-cache'; +const ENTRIES = [ + 'src/chrome-tabs/preload.js', + 'src/help/preload.js', + 'src/main/preload.js', + 'src/settings/preload.js', + 'src/tab-manager/preload.js' +]; + +const parcel = new Parcel({ + entries: ENTRIES, + defaultConfig: '@parcel/config-default', + mode: 'development', + resolvers: [], + targets: { + module: { + // BROWSER ---- + // context: 'browser', + // includeNodeModules: false, + // outputFormat: 'global', + // NODE ---- + context: 'electron-renderer', + // context: 'electron-main', + // context: 'node', + outputFormat: 'commonjs', + sourceMap: false, + distDir: `${BUILD_DIR}/${BUNDLES_DIR}`, + optimize: false, + scopeHoist: false + } + } +}); + +const exec = async () => { + console.warn('This bundled output of this script is not used.'); + console.warn('The script purpose is to experiment bundling preload scripts'); + console.log('Starting Parcel bundling process...'); + await Promise.all(ENTRIES.map(entry => fsp.access(path.resolve(__dirname, entry), fs.constants.R_OK))); + const cacheDir = path.resolve(__dirname, CACHE_DIR); + const buildDir = path.resolve(__dirname, BUILD_DIR); + await Promise.all([cacheDir, buildDir].map(dir => fsp.rm(dir, {recursive: true, force: true}))); + console.log('Cleaned previous build...'); + const {bundleGraph, buildTime} = await parcel.run(); + console.log(`Parcel bundling completed in ${buildTime}ms`); + console.log('Generated the following bundles:'); + bundleGraph.getBundles() + .map(bundle => path.relative(__dirname, bundle.filePath)) + .forEach(file => console.log(` - ${file}`)); +}; + +exec() + .then(() => { + process.exit(0); + }) + .catch(err => { + console.error('Error while creating Parcel bundles'); + console.error(err); + process.exit(1); + });