The proper method for developing Vue components that are dependent on the parent build tools

In my experience, this issue might also arise in other frameworks with plugin/component ecosystems that rely on specific build tools (such as React components with JSX). While Vue serves as my use-case.

Having developed numerous Vue components as single .vue files published on NPM, I have not listed any dependencies in the package.json. These components are designed to operate within a parent project utilizing webpack, vue-loader, sass-loader, and similar tools. You can find an example of such a component here.

I am uncertain about the appropriate method for stating that these components require the parent package to have these build tools. Placing them under devDependencies does not seem right since the components themselves do not depend on these tools during development. While it appears that peerDependencies could be more suitable, I still harbor doubts regarding its compatibility with my intentions.

After browsing through various components on the awesome-vue repository, there seems to be no usage of peerDependencies, and the listed devDependencies pertain to the individual components' development process.

What would be the correct approach when authoring these components? It's almost as if a "peerDevDependencies" category is needed.

Answer №1

Unfortunately, most components are already distributed in compiled form.

In my view, the ideal way to distribute a component is to provide the raw .vue file as the main source code for the component.

It's important not to limit developers to using a specific tool - those who use your package should have the flexibility to choose their preferred tool, whether it be Browserify, Rollup, or Webpack. By providing the raw .vue format, developers can compile the component with their tool of choice and tailor it to their desired Vue version (within compatibility limits).

Additionally, I prefer to offer users the option to immediately use the component, even within a browser, by simply including Vue as a script dependency. This requires compiling the component and defining Vue as a peerDependency that must be present on the page.

To streamline the process further, you can include metadata in the package.json to instruct CDNs to retrieve the compiled version when accessed via a browser. This simplifies usage for the user, allowing them to specify just the package name without concern for file names or versions.

Answer №2

As someone who appreciates Vue.js components as a consumer, I believe that defining your build dependencies as peerDependencies is the optimal approach. While utilizing a common build pipeline, it is crucial to explicitly specify these dependencies. They do not solely belong in devDependencies or dependencies, as their compilation may vary depending on the end user.

Answer №3

To ensure proper configuration, I recommend utilizing the "module" property in the package.json for the raw vue file, and specifying the "main" for the compiled version. The use of the module property is becoming more standardized and is already recognized by webpack and rollup.

For additional information, take a look at this article on setting up multiplatform npm packages.

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

Guide on separating a variable by commas using jQuery

After making an Ajax call to a Java servlet, I am retrieving data and storing it in the 'data' variable upon success. Here is the code snippet: var s1=""; var ticks =""; $('#view').click(function(evt ...

Making an AJAX request in Javascript to retrieve multiple values using the HTTP method 'GET' from a URL

xmlhttp.open("POST","BAConsultRecordsAJAX.php?q="+str,true); Could this be achieved? xmlhttp.open("GET","BAConsultRecordsAJAX.php?q="+str+"j="+str2,true); I need to have values stored in both q and j fields. ...

"Switching from vertical to horizontal time line in @devexpress/dx-react-scheduler-material-ui: A step-by-step guide

Is there a way to switch the Time to a horizontal line using @devexpress/dx-react-scheduler-material-ui? <WeekView startDayHour={7} endDayHour={20} timeTableCellComponent={TimeTableCell} dayScaleCellComponent={DayScaleCell} /> Click ...

the mobile website is not properly aligned on a horizontal axis

As I work on creating a mobile version of my website, I've come across a challenge: The entire site fits perfectly on the computer at a browser width of 480px, but when viewed on my mobile phone (regardless of the browser used), it leaves space on the ...

Issue with Laravel project: Updates made to .vue files are not reflecting in the live environment

Displaying the source code from the site live in dev tools on the right, with the actual content of the .vue file on the server shown on the left. Despite removing nav-bar-icon20 {width:20px; height:20px;}, it still appears on the site. I have attempted ...

Broccoli being served on a secure and encrypted website

After extensively searching, I still haven't found a solution to my problem. I am trying to host files from my local server using broccoli, but when accessing them via a secure (https) URL, my browser gives me an error. Is there a method to serve bro ...

MongoDB error codes and their associated HTTP status codes are important for developers to understand

When a new user attempts to sign up with an existing user account, MongoDb triggers a 11000 error code In Express, handling this scenario can be done as follows: async function signup(req, res, next){ try{ // perform some actions }catch(err){ i ...

In ReactJS, when passing an array of objects to a child component, the first instance may sometimes return as undefined, causing the code to break

Currently, I am in the process of creating a personal blog for my brand. The "Posts" section is designed to retrieve data from a basic JSON via an API. At present, I have used mirageJS to mock the API and employed the useEffect and useState hooks to set th ...

The Swiper library is incompatible with the "vue" version "^2.6.11" and cannot be used together

I've been attempting to incorporate Swiper with "vue": "^2.6.11", however I keep encountering runtime errors. Despite following the instructions on , and modifying the imports as advised: // Import Swiper Vue.js components import { ...

Have the latest updates already been applied, or should you run 'yarn' to install any missing dependencies?

I encountered a strange issue with "ember s" displaying "Missing yarn packages" and listing two missing packages, followed by the instruction "Run 'yarn' to install missing dependencies". However, running 'yarn' resulted in the message ...

What is the method for displaying data from a JSON file that is associated with the wallet address of the authenticated user in next.js?

I am currently working on a claim page using next.js, where logged in Metamask addresses can perform the following tasks: Access data from a local .json file to check eligibility for claiming an item and display the claim page. Submitting a form to update ...

The asyncData function in Nuxt is throwing a surprise setTimeout (nuxt/no-timing-in-fetch-data)

Having trouble running a code on my pages/posts/index.vue page where I keep getting an error message 'Unexpected setTimeout in asyncData'. Can anyone provide assistance in understanding this error and suggest if any additional plugins are needed? ...

An error occurs when trying to modify the classList, resulting in an Uncaught TypeError for setting an indexed property

I am attempting to modify the classes of multiple sibling elements when a click event occurs. Some of these elements may have multiple classes, but I always want to change the first class. Below is the code that I created: let classList = event.currentTa ...

Building a web proxy with node.js and express

I'm currently in the process of designing a personalized web proxy using JavaScript to allow users to surf the internet through a designated website, similar to this . One challenge I encountered is transferring the response from a URL back to the us ...

We regret to inform you that there has been an integration error with Zoom SDK 2,3,5. You have reached the limit set by Zoom. Please verify

I'm currently working on integrating zoom web SDK version 2.3.5 into my Vue app that uses Laravel as the backend. However, I've encountered an error when trying to join a meeting. Here is the error message I received: You have been limited by Z ...

Monitor constantly to determine if an element is within the visible portion of the screen

For a thorough understanding of my query, I feel the need to delve deeper. While I am well-versed in solving this issue with vanilla Javascript that is compatible with typescript, my struggle lies in figuring out how to invoke this function throughout th ...

What is the purpose of NPM requesting peer dependencies if they are already present in the installation?

After updating the AWS-Amplify CLI to the latest version, I encountered an issue with unmet dependencies in NPM. Despite having graphql installed at the correct version, NPM seems to be complaining. Can anyone provide some insight into what might be miss ...

Personalize the layout for vertical table headings and table information

I need help with a table that has vertical headers. I want to remove the extra space within the table header and data cells. Here is the code for my table: <table> <tr> <th class="field">Item ID Number:</th> < ...

Can anyone recommend a reliable JavaScript library for creating resizable elements?

I am looking to incorporate resizable functionality for a textarea. While I have experimented with jQuery UI's "resizable" feature, it doesn't quite meet my needs. I appreciate jQuery, but the resizable option falls short in allowing me to resize ...

Can you please explain the meaning of this error generated by npm-check-updates?

After attempting to start a new project with Vue 3, Vuetify 3, Vue-router, and Pinia, I navigated to my c:\Vue directory where I normally store my source code. From there, I ran the command npm create vuetify. Here's what happened: Vuetify.js - M ...