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

It appears that the pixel sizes are different than what was originally designed

In my project, I have a header panel where the burger button is designed with a width of 32px and height of 24px. .header { display: flex; font-weight: bold; font-size: 50px; height: 100px; border: 1px solid black; position: relativ ...

Utilizing accurate server URLs (Codeigniter) for local JavaScript execution

Help Needed: Issue with Correct Path Names in Local JavaScript with CodeIgniter Backend I am facing difficulties in using the correct path names in local JavaScript while working with a backend in CodeIgniter. -user_data -application -system -assets In ...

Include form data into an array of objects within an Angular data source

I am struggling to add the edited form data from edit-customers-dialog.ts into an array of objects in my datasource. The form.data.value is returning correctly, but I'm facing issues with inserting it properly into the array. As a beginner in Angular ...

Utilizing Codeigniter for transmitting JSON data to a script file

When querying the database in my model, I use the following function: function graphRate($userid, $courseid){ $query = $this->db->get('tblGraph'); return $query->result(); } The data retrieved by my model is then encoded in ...

Node.js on Windows 7: Utilize npm exclusively within the Node.js command prompt

My inquiry pertains to the utilization of Nodejs. After installing Nodejs on Win7 and running it (seeing the green Node.js icon), I attempted to execute the "npm install" command, but it was unsuccessful. I had to switch to the Nodejs command prompt where ...

Clicking will cause my background content to blur

Is there a way to implement a menu button that, when clicked, reveals a menu with blurred content in the background? And when clicked again, the content returns to normal? Here's the current HTML structure: <div class="menu"> <div class=" ...

Sharing data between VueJS2 components

I am working on a project where the parent component retrieves a large JSON object from the server. My goal is to parse this data and then pass it down to the child components. The structure of the child components is as follows: <child-comp /> I ...

JQuery UI autocomplete vanishes instantly without any warning

I am encountering an issue with JQuery UI's autocomplete feature where the dropdown results do not stay visible. While debugging, I noticed that the list briefly appears before disappearing. Below is my code snippet: HTML: <input type="text" plac ...

What is the best way to display two tables side by side in a Vue component?

I am working on a vue application with a photo collection feature. My goal is to display the photos in two tables per row, iterating through the entire collection. Here's an example of what I'm aiming for: <row> &l ...

When running the command "babel server --out-dir build", Babel does not compile .graphql files located within the build directory

Introduction: Our application utilizes Heroku as the server platform. After pushing code, it triggers npm start according to the package.json file. My current nodeJS version on my laptop is v8.16.2, with npm at 6.4.1. In the package.json file: "engines ...

What is the best way to center a heading element within a section on a webpage?

I need assistance aligning the h1 element with the specific class wish to the center of its section, both horizontally and vertically. Unfortunately, I have been unable to achieve this thus far. Any guidance would be greatly appreciated. Below you will fi ...

What is the process for installing private packages with yarn within a Github Action?

My current process: name: Node CI on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [10.x] steps: - uses: actions/checkout@v1 - name: Use Node.js ${{ matrix.node-version }} u ...

Combining vue with deno and vscode: A guide to seamless development integration

How can I set up Visual Studio Code for a Vue project using Deno? Important note - the issues mentioned here only pertain to highlighting in VSCode, as the builds, development, and scripts are functioning correctly! Deno + Vue is an appealing choice! You ...

Having trouble storing radio buttons and checkboxes in MySQL database using AJAX

My app is facing an issue where radio buttons and checkboxes are not correctly entering information into the database. Currently, only text fields are successfully saving data, while checkboxes and radio buttons are only recording the value of the first ra ...

Scrolling using JavaScript's 'smooth scrolling' feature is currently disabled

Background of the Issue: I am in the process of creating a one-page website using Twitter Bootstrap 3 within an ASP.NET MVC project. The Challenge: My current challenge involves implementing 'smooth scrolling' functionality that scrolls to the ...

Incorporate a dynamic avatar into your Navbar with the help of Bootstrap-Vue

I have integrated the Navbar component with Boostrap-Vue and am trying to include an avatar, where the image comes from a variable in the application. The issue I am facing is that I am unable to bind the variable to the avatar component within a slot, as ...

"Enhance the visual appeal of your Vue.js application by incorporating a stylish background image

Currently, I am utilizing Vue.js in a component where I need to set a background-image and wrap all content within it. My progress so far is outlined below: <script> export default { name: "AppHero", data(){ return{ image: { bac ...

Displaying Text and Images on a Sliding Carousel with a Static Background Image

I am currently experimenting with the Materializecss Image Slider. My goal is to have a fixed full-screen background image while the texts and images slide over it. Initially, I tried setting the background-color of the slider class as transparent, but un ...

The sanity upgrade encountered an error as it was unable to locate the necessary package "@babel/plugin-proposal-class-properties@^7.10.4" that is required by "@sanity/core@^2.18.0"

While working on Fedora Linux, I encountered an error after running the sanity upgrade command in my studio folder: ✖ Resolving dependencies ✖ Couldn't find package "@babel/plugin-proposal-class-properties@^7.10.4" required by "@san ...

What is the best way to incorporate a mongoose model into another model?

I have two different models that I am working with. In the user model, I want to include an array of Requests, and in the Request Model, I want to have User as an attribute (without including the password). How can I achieve this? var userSchema = new S ...