Is it possible to install a meteor package for only a specific platform?

Adding a single package called ground:db from https://github.com/GroundMeteor/db to my meteor project is something I'd like to do, but I only want it to be used in the cordova builds. It would be ideal if it didn't clutter up the assets on the web builds.

Is there a way to achieve this?

I've already searched through the meteor add documentation but couldn't find any solution there.

Answer №1

If you want to achieve this, you'll need to create a new package. Here's a simple step-by-step guide:

1) If your project doesn't already have a packages folder, create one

2) Within the packages folder, create a directory named mobileapp

3) Inside the mobileapp directory, create a file called package.js with the following contents:

Package.describe({
   summary: "For cordova use only",
});

Package.on_use(function (api) {
    if(api.versionsFrom) api.versionsFrom("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83cec6d7c6ccd1c3b2adb3">[email protected]</a>");

    api.use(['ground:db'], ['web.cordova']);
});

After that, navigate to your meteor's root directory and run the command:

meteor add mobile

This will ensure that the ground:db package is only added in your cordova builds, without including any unnecessary source code in web builds.

In the Package.on_use method, you can also specify additional files to include using api.add_files with web.cordova as the architecture, ensuring that only specified files are included in cordova builds but not web app builds.

By following this approach, you can optimize your web app without compromising its functionality.

Answer №2

View here the package.js file for ground db.

Attempt to substitute the api.addFiles with the following:

api.addFiles([
    'groundDB.client.js',
    'wrap.collection.js',
    'wrap.eventemitter.js',
    'wrap.proto.eventemitter.js',
    ], 'web.cordova');
  api.addFiles('groundDB.server.js', 'web.cordova');
});

For more insights, refer to this additional information from this Github query.

Currently within a package, you can:

api.addFiles('foo.js', 'web.cordova'): include foo.js only in Cordova/Phonegap builds.
api.addFiles('bar.js', 'web.browser'): include bar.js specifically in browser builds.
api.addFiles('baz.js', 'web'): include baz.js in all client builds.
as well as:

api.use('foo:bar', 'web.cordova'): utilize the package API solely in Cordova/Phonegap builds.
api.use('foo:bar', 'web.browser'): use the package API only in browser builds.
api.use('foo:bar', 'web'): apply the package API in all client builds.

Verify if it functions correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The jQuery dialog dropdown list fails to display on subsequent attempts

I'm currently utilizing a jQuery modal dialog to showcase a drop-down list for users to make selections from. By dynamically populating the drop-downs through adding them to the empty list, I encounter an issue where it only displays the default optio ...

HTML drag-and-drop setDragImage fails to show ghost image on initial drag operation

Currently, I am working on developing a drag and drop menu feature that allows users to drag an image thumbnail from one div to a canvas element. The main issue I am facing is that the source div uses a sprite for displaying its background thumbnail. As a ...

Creating numerous hash codes from a single data flow using Crypto in Node.js

Currently, I am developing a Node.js application where the readable stream from a child process' output is being piped into a writable stream from a Crypto module to generate four hash values (md5, sha1, sha256, and sha512). However, the challenge ari ...

Refresh the view in AngularJS following a successful $http.get request

I have a <ul> in my HTML view that is populated based on a $http.get request. HTML: <div id="recentlyReleased" ng-controller="sampleRecordController as recCtrl"> <h1>Sample Records</h1> <ul> <li class= ...

What is the best way to perform a pure JavaScript forEach loop and display the output with Firebase?

I am attempting to retrieve data from a firebase database and display all of the results. I am used to using jquery's appendTo function for this task, but I am unsure how to achieve the same result with pure javascript. Below is my current script: & ...

Mocha test failing to trigger function execution

I've been developing an Express.js application that includes a feature for creating appointments with a post request. This feature involves retrieving and saving data from a third-party API, followed by sending updated API data in the subsequent reque ...

What is the best method for transferring states between components?

When it comes to React JS, I am a beginner looking to develop a ToDo list application. In my project, I have the main page App.js, where I created the component MainBlock. This MainBlock component structures the layout into left and right sides. On the rig ...

How to optimize JSON responses Using PHP

I have a straightforward MVC model. During an Ajax request, I send data to be processed by PHP and retrieve database records in JSON format. Since the object can be quite large, I am looking for a way to compress/encrypt it on the server-side in PHP and de ...

Organizing an array of objects within MUI cards based on social media platforms

I'm currently developing an application that showcases athlete data in a grid layout using MUI Grid. The colored borders on the left side of each card are determined by the corresponding social network associated with that athlete. https://i.sstatic. ...

What is the process for searching a specific column in a Vuetify v-data-table that is not included in the headers?

Header for Product Data: headers: [ { text: "Product Name", value: "name" }, { text: "Quantity", value: "quantity" }, { text: "Price", value: "price" }, { text: "Orders", value: &quo ...

ReactJS popover element - property pushing and event management

I'm currently developing a reactjs application, and I'm working on creating a modular popup component. The goal is to have the button appear as a combination of a badge and an icon, triggering the popup menu on hover rather than on click. Here i ...

Comparison: NumberFormatter versus NumberFormat in PHP and JavaScript

My attempts to format currency seem to yield inconsistent results. Using PHP with the NumberFormatter class, here's a snippet of my code: $number = 5125.99; echo getInternationallyFormattedCurrency($number, 'tl-PH', 'PHP'); echo & ...

Determine if the input number exceeds a specified threshold by implementing JavaScript

My attempt at performing calculations on a page is not yielding the desired results. I have tinkered with the code below, but it doesn't seem to be working as expected. Can anyone provide guidance on where I might be going wrong? Specifically, I want ...

Is it possible to automate the firing of setTimeout events using WebDriver?

Looking to test pages with numerous setTimeout functions, I'm searching for a way to expedite the code execution upon page load rather than waiting for it to run on its own. One idea is to inject custom JavaScript like this into the page before evalu ...

Stop the selection of text within rt tags (furigana)

I love incorporating ruby annotation to include furigana above Japanese characters: <ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby> However, when attemp ...

Working with arrays and elements in JavaScript using regular expressions

The programming language is JavaScript. Imagine we have an array filled with positive and negative integers mixed in with other letters (e.g. 1a or -2d). The challenge is to figure out how to select all the strings that start with or contain positive inte ...

Problem with BehaviorSubject: next() method is not functioning as expected

My goal is to utilize an angular service for storing and communicating data via observables. Below is the implementation of my service: public _currentLegal = new BehaviorSubject({ name: 'init', _id: 'init', country: 'init& ...

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

Creating interconnected circles with lines utilizing canvas

I am currently utilizing the canvas tag to generate circles on a world map image. My objective is to link these multiple circles with lines using the Canvas tag. Although I have successfully drawn the circles, I am facing difficulty in drawing the connecti ...

What is the significance of the abbreviation 'dbo' in a MongoDB - Express application?

Below is the code snippet provided: app.js const express = require("express"); const app = express(); const cors = require("cors"); require("dotenv").config({ path: "./config.env" }); const port = process.env.PORT | ...