Compiling Vue Component with Laravel Webmix: Troubleshooting JS Compilation Issue

I am currently experiencing an issue with compiling JS in a specific order. I need to compile the library or custom JS first, but the problem is that Laravel webmix compiles Vue components before the custom JS.

When I execute the command npm run dev, all the JS files are merged into a single file at public/js/app.js.

Unfortunately, the Vue components are added before the custom.js code. I want to prioritize compiling the custom.js code before the Vue component code.

app.js

require('./bootstrap');
require('./custom');

window.Vue = require('vue');

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('product-list', require('./components/ProductListComponent.vue').default);
Vue.component('cart', require('./components/CartComponent.vue').default);

webpack.mix.js

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

Answer №1

Main Application Code

require('./bootstrap');

window.Vue = require('vue');

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('product-list', require('./components/ProductListComponent.vue').default);
Vue.component('cart', require('./components/CartComponent.vue').default);

Custom Scripts

require('./custom');

window.Vue = require('vue');

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('product-list', require('./components/ProductListComponent.vue').default);
Vue.component('cart', require('./components/CartComponent.vue').default);

Webpack Configuration

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
   .js('resources/js/custom.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

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

While in the process of developing a React application, I have encountered the following challenge

PS F:\Programming Tutorials Videos\R Practice> npx create-react-app custom-hook npm ERR! code ENOTFOUND npm ERR! syscall getaddrinfo npm ERR! errno ENOTFOUND npm ERR! network request to https://registry.npmjs.org/create-react-app failed, reaso ...

Implementing the 'not-allowed' cursor style on disabled rows in Material UI datagrid

I have a specific disabled row in a Material UI data grid where users are unable to select or perform any actions on it. I am looking to display the cursor as "not-allowed" on this particular row. How can we apply styling to only this row since there is no ...

Watching for changes to an element's visibility within the viewport and automatically scrolling it

I'm having trouble making the input scroll to .here when its value matches "1". Even though I tried using a button with a handle-click function and it worked. Please lend me a hand with this issue. <template> <button @click="scrollToV ...

Apply a static style to every rendered component just one time

Is there a way for me to individually style each card image only once? For example, I want to apply a transform style via a function in CSS; I want the image to maintain its original value, but when a new component is rendered, that card should have a di ...

Detection of NTLM error during the parsing of the Authorization header

After posting a question here, I discovered that the issue causing the error was not related to my axios request. Unfortunately, I'm unsure how to close the question. An error occurs when attempting to send an Axios Get request to my express backend ...

"Experience the new Bootstrap 5 feature: Off-Canvas sliding from left to

I encountered the code snippet below on the official bootstrap 5 demo. Despite my efforts, I am struggling to figure out how to relocate the off-canvas menu from Left-to-Right. The divergence between the documentation code referencing offcanvas-start and t ...

TS1057: It is required that an async function or method has a return type that can be awaited

There was a recent Github issue reported on March 28th regarding async arrow functions generating faulty code when targeting ES5, resulting in the error message: TS1057: An async function or method must have a valid awaitable return type You can find t ...

Prevent users from uploading files when submitting the form

When I have a form with text and file inputs that submits an ajax request, I need to temporarily disable the inputs while sending the request. After the request is sent, I want to enable them again for another submit. Disabling text inputs is straightforw ...

What is the best way to link optional and undefined paths in AngularJS routing?

When it comes to AngularJS routing, I have a question. How can we combine the use of a star (*) to match paths with slashes and a question mark (?) to match optional paths? Specifically, I am looking to match both /admin/tasks and /admin/tasks/arbitrary/pa ...

Having trouble with jQuery attribute selectors? Specifically, when trying to use dynamic attribute

This is the code I am working with $("a[href=$.jqURL.url()]").hide(); $.jqURL.url() fetches the current page URL. Unfortunately, this code is not functioning as expected. Is there a way to dynamically select elements? ...

Creating a mapping strategy from API call to parameters in getStaticPaths

I am attempting to map parameters in Next.js within the context of getStaticPaths, but I am facing issues with it not functioning as expected. The current setup appears to be working without any problems. https://i.stack.imgur.com/LeupH.png The problem a ...

Using Angular 4 to delete selected rows based on user input in typescript

I am facing a challenge with a table that contains rows and checkboxes. There is one main checkbox in the header along with multiple checkboxes for each row. I am now searching for a function that can delete rows from the table when a delete button is clic ...

Angular directive ng-if on a certain path

Is it possible to display a specific div based on the route being viewed? I have a universal header and footer, but I want to hide something in the header when on the / route. <body> <header> <section ng-if=""></section&g ...

The Google Books API has encountered an authentication error with status code 401

Trying to access public data using the Google Books API locally: An error occurred with the authentication credentials. It seems that an OAuth 2 access token, login cookie, or another valid authentication credential is missing. For more information, visit ...

What is the best approach for implementing form validation that is driven by directives in AngularJS?

Currently, I am working on creating a registration form using AngularJS. I need to use the same form in four different sections. To achieve this, I have created a common form within a single HTML page as shown below: <div> <div> < ...

The program encountered a 'TypeError: education.map is not a function' error when trying to generate the page. All console logs related to this issue will be shown in

Hey everyone, I'm currently working on a project in Next.js with a main file named Project.js. I'm running into some issues trying to export data from the main file to an object called Resume for the education section component... import EduSecti ...

Utilizing date-fns in place of dayjs for developing a personalized calendar header for MUI Date Picker

I'm currently facing issues while trying to switch the default dayjs type to date-fns for a custom calender header in the MUI Date Picker component. Below is my Date Picker component along with the custom header component: <StyledDatePicker ...

Mongoose and BlueBird emerge victorious from fulfilling their promise

When using mongoose and bluebird as a promise framework, I encounter an error whenever I use "save" or "remove": Warning: a promise was created in a handler but was not returned from it I have spent days trying to resolve this issue. I have tried various ...

Placing a user's username within an ejs template using express and node.js

Currently, I am attempting to integrate the username into a layout using ejs templating with node and express. Below are the steps I have taken: Mongodb model: const mongoose = require('mongoose') const Schema = mongoose.Schema; var uniqueValid ...

Executing an external Python script through an HTML button from a location outside the Django project

I'm encountering an issue when attempting to run a Python script through an HTML button. The error message I receive is: module 'sys' has no attribute 'execute' In my views.py, I have the following code: from subprocess import r ...