Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
How to precompile Vue objects in js files?

I have an Electron project and I am using webpack as a module bundler, here is the relevant code and configuration for my project.

webpack.config.js:

const path = require('path')
const {VueLoaderPlugin} = require("vue-loader")

module.exports = {
    mode: "development",
    entry: path.join(__dirname, 'src/index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: "bundle.js"
    },
    plugins: [
        new VueLoaderPlugin()
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: [
                    {loader: "vue-loader"}
                ]
            },
            {
                test: /\.css$/,
                use: [
                    {loader: "vue-style-loader"},
                    {loader: "css-loader"}
                ]
            }
        ]
    }
}

src/index.js:

import Vue from 'vue'

new Vue({
    template: '<h1>{{ message }}</h1>',
    data: {
        message: "Hello World"
    }
}).$mount('#app')

src/index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello World</title>
</head>
<body>
<div id="app"></div>

<script src="../dist/bundle.js"></script>
</body>
</html>

I know it can be configured in webpack.config.js:

resolve: {
    alias: {
        'vue$': 'vue/dist/vue.esm.js'
    }
}

But the Vue object in index.js is just an entry, I don't want to use vue.esm.js for such a little code to run smoothly, I want to use vue.runtime-only.js, but it needs to precompile the template .

How can I precompile this Vue object?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have found a solution, there is no way to directly compile the Vue object in the js file.

But you can extract the template of the Chinese Vue object in index.js into the App.vue file:

<template>
  <div>
    <h1>Hello World.</h1>
  </div>
</template>

index.js imports App.vue.:

import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

new Vue({
    // Load the precompiled template with render .
    render: h => h(App)
}).$mount('#app')
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!