Are there any ES module versions of Vue Devtools available, or is there a production-ready ES module version of Pinia that is dependency

Attempting to utilize pinia 2.1.7 as an ES module alongside Vue 3.3.8.

Thus:

<script type="module" src="./js/lib/vue-3.3.8.esm-browser.js"></script>
<script type="module" src="./js/lib/pinia-2.1.7.esm-browser.js"></script>

and:

import {defineComponent, createApp, nextTick} from "./lib/vue-3.3.8.esm-browser.js";
import {createPinia, setActivePinia} from "./lib/pinia-2.1.7.esm-browser.js"

and:

...
const pinia = createPinia();
setActivePinia(pinia);

const cntApp = createApp(App);
cntApp.use(pinia);
cntApp.mount('.vue-app');
...

This is my current understanding.

I've learned that the pinia ES module requires vue-demi and vue/devtools-api. I have successfully imported vue-demi as an ES module from the npm dist folder, but I am unable to locate the ES module for devtools.

Working within a CMS that functions best with single pages, I aim to stick with importing each page as an ES module until necessary to create a large JS package.

Queries:

  • Is there a production version of pinia available without vue-demi and api tools?
  • Can devtools be included as an ES module or script?

Answer №1

If you find yourself navigating the node universe and utilizing tools like npm, webpack, or others, rest assured that your scripts will be equipped with all necessary components.

However, in a specific project setup:

  • You must load individual ES modules directly into the browser
  • You are unable to utilize resources like unpkg.com as the final output will be integrated into a hybrid mobile app
  • Your goal is to ensure that only essential code is included in the end product

In this scenario, careful selection and adjustments are required. Personally, I am using Vue3 and Pinia, hence I opt for ES module imports within the browser.

Here are some recommended steps:

  1. Begin by downloading the necessary modules through npm following the documentation; for instance, npm install pinia, npm install vue-demi, npm install vue/devtools-api if necessary. If you are new to this process, consider creating a dummy npm lib folder and performing npm install there to gather all packages.

  2. Copy the required files into your project and load them in the browser as modules. As an example, my current setup includes:

     <script type="module" src="./js/lib/vue-3.3.8.esm-browser.js"></script
     <script type="module" src="./js/lib/vue-devtools-6.5.1.esm/index.js"></script>
     <script type="module" src="./js/lib/vue-demi-0.4.16.esm.js"></script>
     <script type="module" src="./js/lib/pinia-2.1.7.esm-browser.js"></script>
    

The necessary files can typically be found within the packages, usually under subfolders such as "dist" or "lib". Your own ES module file might reside in a directory like:

E:\Users\Peter...\Documents\.....\npmlib\node_modules\pinia\dist\pinia.esm-browser.js

  1. Vue demi serves as a simple script that mainly imports and exports elements from Vue, while adding functionalities like set() and del() to the interface, along with other modifications for Vue3 compatibility. To create your own ES module, you'll need to tweak the index files accordingly. My approach involves extracting /lib/v3/index.mjs from the package root, adjusting the import statement paths, and saving it as vue-demi-0.4.16.esm.js.

  2. Since these files are primarily designed for package managers, adjustments to the import statements' from section become essential. The browser needs to locate the referenced files correctly.

When examining pinia.esm-browser.js, we notice that many imported names stem from Vue.js except set and del, which originate from vue-demi. In essence, there is no oversized/vue-demi script to hunt down; vue-demi simply acts as a conduit for importing features from Vue.

For example, my pinia-2.1.7.esm-browser.js now contains:

//import { hasInjectionContext, inject, toRaw, watch, unref, markRaw, effectScope, ref, isVue2, isRef, isReactive, set, getCurrentScope, onScopeDispose, getCurrentInstance, reactive, toRef, del, nextTick, computed, toRefs } from 'vue-demi';
import { hasInjectionContext, inject, toRaw, watch, unref, markRaw, effectScope, ref, isVue2, isRef, isReactive, set, getCurrentScope, onScopeDispose, getCurrentInstance, reactive, toRef, del, nextTick, computed, toRefs } from "./vue-demi-0.4.16.esm.js";

//import { setupDevtoolsPlugin } from '@vue/devtools-api';
import { setupDevtoolsPlugin } from "./vue-devtools-6.5.1.esm/index.js";

A glimpse at vue-demi-0.4.16.esm.js reveals:

import * as Vue from "./vue-3.3.8.esm-browser.js";

var isVue2 = false
var isVue3 = true
var Vue2 = undefined

... Remainder of the content remains unchanged ...

export * from "./vue-3.3.8.esm-browser.js";
export {
  Vue,
  Vue2,
  isVue2,
  isVue3,
  install,
}

All the necessary elements are present; adjust and align them with appropriate export statements.

There are more sophisticated approaches available for enhancing flexibility in import statements, publishing, and updating procedures. Nonetheless, the fundamentals shared here are functional.


Edit 02.12.23 Once you have identified the requisite files, refrain from altering third-party code solely to match import statements. Instead, as highlighted by @Estus Flask's comment, utilize the import map feature for seamless integration. Here's how:

<script type="importmap">
    {
        "imports":{
            "vue": "./js/lib/vue-3.3.8.esm-browser.js",
            "vue-demi": "./js/lib/vue-demi-0.4.16.esm.js",
            "@vue/devtools-api":"./js/lib/vue-devtools-6.5.1.esm/index.js"
        }
    }
</script>

By implementing the import map, even third-party entities will seamlessly access the unaltered files.

Note that the import map necessitates adherence to strict JSON syntax rules, unlike pure JavaScript. For instance:

"imports":{ ... }

is valid, whereas:

 imports: { ... }

would not comply due to JavaScript's requirements for property names, contrasting with import map's JSON prerequisites.

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

Node JS Axios Network Error due to CORS Policy Restrictions

When attempting to make a put axios request, I encounter the following error: https://i.sstatic.net/aBQGI.png I have installed and enabled the CORS module in the server.js file, but it doesn't seem to be working. Additionally, there are no CORS head ...

When utilizing an object as state in React, the `setState` function will only set

Currently, I am working on developing a React form that utilizes a custom Input component which I have created multiple times. The objective is to gather all the names and values from the form in the parent component: {inputName: value, inputName2: valu ...

Remove elements from an array in Typescript if they are not present in a nested array

I am struggling with filtering values from a single-dimensional array based on id matches in an array of objects. array1 = [1, 3, 15, 16, 18]; array2 = [ { id: 1, dinner : pizza }, { id: 15, dinner : sushi }, { id: 18, dinner : hummu ...

Establishing Routing for Angular within an ASP.NET Web API 2 application

Currently, I am facing difficulties in setting up the routing for my project. There are several cases that need to be handled, but I am struggling to make them work as intended. case 1: / - Should route to the index of the angular app Case 2: /{angular ...

Utilizing setTimeout within every iteration is ineffective

A vast gallery containing around 400 pictures is featured on my website. I have implemented a button that allows users to delete all images from both the DOM and the server through an AJAX request for each file. While testing, I attempted to use the setTi ...

Adding a specific element to an array using JQuery

I am in the process of developing a web application using jQuery to track goals and habits. Users can set a main goal such as 'Discipline' and then add sub-goals or habits related to that main goal (e.g. 'exercise every day'). Organizi ...

Adjusting the content within a text area using an AngularJS service

I am currently editing text in a textarea within the admin view and I would like to display it through an angular service on the user view. However, I want the text to be displayed in multiple rows, maintaining the same format that I entered in the textare ...

SCRIPT5007: The property 'href' cannot be assigned a value as the object is either null or undefined

This script is functioning properly in browsers like Chrome and Firefox, however it is encountering issues when used with Internet Explorer. An error message is displayed in the IE console: SCRIPT5007: Unable to set value of the property 'href': ...

The clientWidth property of a div element in React is coming back as null when accessed in the

I'm facing an issue with a React component that contains an image. I require the dimensions of the image (not the window dimensions) for some other operations involving the image element. Everything works fine when I initially render the component, bu ...

How can I show the total sum of input values in a React.js input box?

Is there a way to dynamically display the sum of values entered in front of my label that updates automatically? For example, you can refer to the image linked below for the desired output Output Image I have initialized the state but I'm struggling ...

Issue encountered in AngularJS while configuring resources for the action `query`: Anticipated response was an object, but received an array instead

I've been attempting to utilize Angular 1.3 to access a REST service, but I keep encountering an error stating "Error: error:badcfg Response does not match configured parameter". My suspicion lies in the controller where I invoke $scope.data. Even th ...

What is the best way to transition an absolute positioned element from right to center?

When hovering over an overlay element, I want the <h3> tag to appear with a transition effect from right to center, similar to the example shown here. Could someone please assist me in achieving this? Thank you in advance. HTML <div class="row m ...

Are ref() and watch() together the same as computed() in Vue 3?

I am working with a dynamic object team that contains a property players I am looking to make the players property reactive (to enhance usability by exporting it from a customized hook). Can these two code snippets be considered equal? (I assume they a ...

What is the best way to extract a URL parameter from the parent page and pass it to an iframe using JavaScript?

Currently, I have embedded a form within an iframe on a specific landing page. Visitors arriving at this landing page through an affiliate link will have a parameter added to the URL (http:thelandingpage.com?c3=1). After they submit the form within the ifr ...

Is there a way for me to direct to a different HTML page once I click on a certain data point?

At the moment, I have been utilizing this complete set of calendar codes. <!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <link href='fullcalendar.css' rel='stylesheet' /> <link href=&a ...

What is the most effective way to construct this array?

I have an array of objects that contain multiple properties: [ { a: 3, b: 2, c: 5, d: 6, e: 8 }, { a: 1, b: 5, c: 3, d: 1, e: 2 } ] My goal is to extract only the values of specific properties and create a new array without the objects. For example, ...

A guide on retrieving an integer from a JavaScript prompt using Selenium with Python

Currently, I'm attempting to develop a prompt that asks the user for a number on a webpage by utilizing Selenium in Python. Below is the code I've implemented, however, it is returning a None value. driver = webdriver.Chrome() driver.get(' ...

What is the method for deactivating the voting button for a product review when the review's ID is present in local storage?

Managing reviews with user voting in a React app can be challenging. Each review can be deemed helpful or not, and each product may have multiple reviews. When a user votes on a review, the corresponding button should be disabled. I store the clicked revie ...

Issue with an unknown cause (AJAX / GET)

Let's break it down, here's the code I'm working with. It's meant to update the "like" column in my "comments" table. The issue arises when trying to submit the result in JavaScript. There's a SPAN containing a link to submit: &l ...

Encountered an error while handling a promise: Unable to access null properties (specifically, 'useState')

I'm having trouble understanding why I keep encountering this error with the line const [isLoading, setLoading] = useState(true);. It's initially set to true so it shouldn't be undefined. export default async function GetProducts() { c ...