DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How To Build a Google Photos Clone - Part 1
  • Build a Java Backend That Connects With Salesforce
  • Manage Microservices With Docker Compose
  • The Technology Stack Needed To Build a Web3 Application

Trending

  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • GDPR Compliance With .NET: Securing Data the Right Way
  • A Guide to Developing Large Language Models Part 1: Pretraining
  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security

Vue JS Application Without Build

How to build a simple Vue JS web application without pains and complexities of a build process. This proposal shows a way to introduce a modern web framework in a gentle and gradual way, easy to grasp even for an unexperienced developer.

By 
Tomasz Waraksa user avatar
Tomasz Waraksa
DZone Core CORE ·
Aug. 19, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
15.2K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

People would often say how Vue JS or React are simple, even trivial.

Well... I for one disagree ;-). They're not simple. After all, they're widely used to build massive, often mission-critical systems. There's plenty to learn beyond these wildly optimistic Learn React in a Day courses. Their ecosystems are huge. Tooling is demanding. Documentation is extensive. It takes substantial effort to discover and understand best practices and efficient design patterns.

What's their appeal then? For me, it's their progressive character. Complexity is introduced into the project gradually, only when it becomes necessary. I can start with simple JavaScript, a few prerequisites, and without a complex build setup. Then, as my needs grow, I start adding new concepts and learn how to use them. Things such as modules, components, routing, state management, state propagation, async code, reactivity, server-side rendering — they all eventually come into picture. But only when their time comes, and only when I'm ready for them!

Source code for the article can be found at https://bitbucket.org/letsdebugit/minimalistic-vue

Simple Tools for Simple Projects

When I begin a new project, it's crucial that it's simple to start. Cognitive load of this profession is already hard enough. I don't need any more of it, unless truly necessary.

Equally important is that project setup stays simple, as long as the application remains simple. For many projects, all that I will ever need is a little smart engine behind a web page. Something to wire up a photo gallery. Something to fetch updates from an external source and keep the UI in sync. Why would I introduce TypeScript and webpack just for that? But Vanilla JS comes at a significant cost. I love having things such as state management, reactivity, and data bindings. They save so much time, and they help building a consistent UI.

Luckily, this is possible with progressive web frameworks. In the example below, I want to show how to introduce Vue JS and enjoy its powers in a simplest possible way.

Application Design

The example below is a tiny one-page web application. It has a header, content area and a footer. In the content area there's a message and a button. When user clicks on the button, the message changes:

simplified UI

As a prudent programmer, I want to properly structure my application from the very beginning. There are the following elements in the UI:

  • header
  • main area
  • footer

I'd love to have each of these defined as a separate component. I'd like to keep their code in separate modules, easy to identify and work with.

In a typical Vue JS setup, you'd use single-file .vue components for that. This unfortunately requires a build process based on webpack, rollup, etc. It turns out that you can get nearly the same experience without any build process! It maybe isn's as comprehensive as the original deal, but it's just fine for many simple scenarios. More important, it has none of complexities and dependencies introduced by a regular build process and CLI tools.

Project Structure

The project is structured as follows:

Plain Text
xxxxxxxxxx
1
12
 
1
index.html
2
    index.js
3
    index.css
4
    header/
5
        header.js
6
        header.css
7
    content/
8
        content.js
9
        content.css
10
    footer/
11
        footer.js
12
        footer.css


Our logical UI components are clearly reflected in the physical structure of the project.

Bootstrapping

When browser loads index.html, the following happens:

  •  Vue JS library is fetched from CDN repository at https://unpkg.com/vue
  •  Component stylesheets are fetched
  •  Application module is imported from index.js and executed

Notice how we used <script type="module"> to tell the browser that we're loading modern ES6 code with all the bells and whistles!

When index.js is executed, it imports subsequent modules which contain our components:

  • Content from /content/content.js
  • Header from /header/header.js
  • Footer from /footer/footer.js

Components

The components are not much different from regular Vue JS single-file components. They can have all the features and functionality of a Vue JS component, such as:

  • data
  • props
  • methods
  • computed properties
  • lifecycle events
  • slots
  • template with markup
  • etc.

Because there is no build process, our components have to be put together in a different way. Modern JavaScript features will help us here. Instead of bundling, we can simply import the required dependencies wherever needed. After all those years of mindless bundling browsers finally know how to import modules ;-) Then, instead of a <template> block we will use JS template literals.

Component code is structured as follows:

JavaScript
xxxxxxxxxx
1
17
 
1
const template = `
2
  <div>
3
  ...
4
  </div>
5
`
6
7
export default {
8
  template,
9
10
  data () {
11
  },
12
13
  computed: {
14
  },
15
16
  // etc.
17
}


The main application component is defined in the index.js file. Its task is to assign custom HTML tags such as <app-header> or <app-footer> to all our components. 

JavaScript
xxxxxxxxxx
1
15
 
1
import Header from './header/header.js'
2
import Content from './content/content.js'
3
import Footer from './footer/footer.js'
4
const App = {
5
  el: 'main',
6
  components: {
7
    'app-header': Header,
8
    'app-content': Content,
9
    'app-footer': Footer
10
  }
11
}
12
window.addEventListener('load', () => {
13
  new Vue(App)
14
})
15


These custom tags are then used to build our application UI in the index.html file. We ended up with a UI which is trivially simple to read:

HTML
x
31
 
1
<!doctype html>
2
<html>
3
4
<head>
5
  <meta charset="utf-8">
6
  <title>Minimalistic Vue JS</title>
7
  <link rel="stylesheet" href="index.css">
8
  <link rel="stylesheet" href="header/header.css">
9
  <link rel="stylesheet" href="content/content.css">
10
  <link rel="stylesheet" href="footer/footer.css">
11
12
  
13
14
  
15
</head>
16
17
<body>
18
  <main>
19
    <app-header bg-color="#c5cae2">
20
    </app-header>
21
22
    <app-content>
23
    </app-content>
24
25
    <app-footer>
26
      (c) Tomasz Waraksa, Dublin, Ireland
27
    </app-footer>
28
  </main>
29
</body>
30
31
</html>

Summary

In the end, we have nearly the full power of Vue JS without any complexities of a build process. To deploy this application we would simply copy the files to a web server. Then just hope that our visitors will use a decent browser ;-)

References

The article is also available at my blog Let's Debug It.

The complete source code can be found at https://bitbucket.org/letsdebugit/minimalistic-vue. Feel free to clone and reuse this code. Any suggestions or questions are most welcome!

All credits and thanks go to the creators of the awesome Vue JS framework.

application Build (game engine)

Published at DZone with permission of Tomasz Waraksa. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Build a Google Photos Clone - Part 1
  • Build a Java Backend That Connects With Salesforce
  • Manage Microservices With Docker Compose
  • The Technology Stack Needed To Build a Web3 Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!