Can a Vue app be created as a standalone application?

Can a Vue application be created without requiring Vue as a runtime dependency?

For example, rather than having the browser load vue.js and the app like this

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://www.myxyzhost.com/my-app.js"></script>

is it possible to have my-app.js already include vue.js, making it a simple one-liner script inclusion in a web page?

<script src="https://www.myxyzhost.com/my-app.js"></script>

Answer №1

It turned out to be much simpler than expected:

All I had to do was create a separate entry file for webpack:

my-custom-component-entry.js

Then, I added everything I needed in that file (Vue and the custom component):

// Here is the solution I've been searching for.
import Vue from 'vue';
import MyCustomComponent from './components/my-custom-component.vue'; 

new Vue({
  components: {
    'my-custom-component': MyCustomComponent
  } 
}).$mount('#app'); // Make sure there's a #app element somewhere in your HTML

After that, I built it with webpack (I won't go into details here).

Now everything is bundled in one file. There's no need for a separate Vue runtime for customers to install. All you have to do is:

<script src="https://www.myxyzhost.com/dist/my-custom-component.js"></script>

Of course, make sure to add the necessary polyfills for Internet Explorer to prevent any issues.

The best part is that for modern browsers, it's just a one-liner, making it easier to market. That's all I needed.

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

Ways to trigger an npm script from a higher-level directory?

After separately creating an express-based backend (in folder A) and a react-based front-end project (in folder B), I decided to merge them, placing the front-end project inside the back-end project for several advantages: No longer do I need to manu ...

`npm run build` fails to create the `index.html` file

Upon executing the command npm run build in my Vue.JS project, I noticed that there is no index.html file in the dist directory. The contents of my webpack.base.config.js file are as follows: // Your webpack base config code here // ..................... ...

What is the most effective way to toggle the visibility of div elements using jQuery?

I am currently working on a small project centered around interviewing people using short GIF animations. I want the viewers to have 10 seconds to watch the GIF, but I've noticed that the timer is not accurate in my code. After some research, I came ...

Having difficulty accurately interpreting the input value

As someone new to JavaScript, I set out to create a basic calculator using JavaScript and HTML. My goal is to have two input fields, named Fld1 and Fld2, that would add up the values entered into them when submitting. However, despite parsing the input val ...

Include an external JavaScript file within a component to display pictures in a web browser using Angular 2

I am developing a website using Angular 2 and need to incorporate a JavaScript file into a component. The goal is for this script to adjust the height of certain images to match the height of the browser window. What is the best way to integrate this scri ...

Adjust image size as the page is resized

My challenge is to resize images that are typically too large for the current window size, ensuring they fit within 85% of the client window. I tried creating a function utilizing onload and onresize events but encountered issues. function adjustImages(){ ...

Tips for using JavaScript to consume a complex type returned by a WebMethod on the client side

I am new to Webmethods and Services and I find myself in a bit of a predicament here. The webmethod I have returns an instance of the StatusViewModel class. [WebMethod()] public static StatusViewModel GetTime1() { Debug.Write("Timer") ...

Accessing the session object within an Express middleware function is crucial for

This is my unique Express middleware setup: var app = express() .use(express.cookieParser()) .use(express.session({secret: 'HiddenSecret'})) .use(express.bodyParser()) .use(function displaySession(req, res, next) { consol ...

Experience simultaneous background and foreground events with fullcalendar-vue

Currently, I am working with the fullcalendar-vue component to schedule events. In this case, the background events represent unavailable timeslots, while users can add events to available timeslots on the calendar. I have two event sources: A bound rea ...

Switching from map view to satellite view on Google Maps allows you to see detailed aerial

Is there a way to switch from map view to satellite view on a Google Map using JavaScript after zooming in 100%? If so, how can it be achieved within the following JavaScript code? DEMO:http://jsfiddle.net/keL4L2h0/ // Load Google Map ///////////////// ...

What is the best way to define a variable within a function?

Here's a function designed to verify if the username has admin privileges: module.exports = { checkAdmin: function(username){ var _this = this; var admin = null; sql.execute(sql.format('SELECT * FROM tbl_admins'), (err, result, fields ...

Converting a Jquery object into a Javascript object

Can someone help me decipher this piece of code? //... obj.dd.on('click', function(event){ $(this).toggleClass('active'); return false; }); //... $(function() { var dd = new DropDown( $('#dd') ); $(doc ...

Discovering the art of interpreting the triumphant outcome of an Ajax request with jquery/javascript

I recently encountered a challenge with my function that deals with a short JSON string: <script id="local" type="text/javascript"> $( document ).ready(function() { $('tr').on('blur', 'td[contenteditable]', functi ...

Error message: npm command not recognized while running commands within an Electron application

While developing an electron app, I utilize shell commands with child_process.exec. One of the commands I use is npm run start, which functions perfectly in a development environment. However, upon building the application for production, all npm commands ...

Guide on updating location and reloading page in AngularJS

I have a special function: $scope.insert = function(){ var info = { 'username' : $scope.username, 'password' : $scope.password, 'full_name' : $scope.full_name } $http({ method: &ap ...

In search of the most efficient method for integrating an AJAX-powered TreeGrid feature

Can anyone recommend an Ajax/TreeGrid implementation that meets the following criteria: Must support server side sorting Should be able to load leaf nodes on demand, meaning only children of open nodes are loaded Needs to support paging so that nodes are ...

Guide on integrating a JavaScript control (JavaScript package) obtained from GitHub into my asp.net application

Hello everyone, I am a newcomer to GitHub and have some basic questions to ask. Recently, I downloaded the package from https://github.com/jspreadsheet/ce in .zip format for using in my asp.net web application. However, I am not sure how to incorporate the ...

Transfer the value of a variable within the local scope to the dragstart event handler during the dynamic generation of an input element

After going through several similar questions, I couldn't find a solution that applies to my specific case. Here is the loop I am working with: $.each(data.modules, function(i, field) { let $li = $(`<li><div> Name: ${field.name}</div& ...

Could my object exports be the issue? I'm new to JS and struggling to figure out why my test is not passing

Just dipping my toes into the world of Javascript and currently tackling objects and test driven development in my classes. I've encountered a bit of trouble with my code and tests - not quite sure why they're failing. Initially, everything work ...

Tips for editing bootstrap-vue table columns using non-Latin characters?

I need to create a table using the Cyrillic alphabet, but the keys of the object must be in the Latin alphabet within the program. Example : export default { data() { return { wmsFields: ['№', 'Наименование', ...