Webpack packaged the vue project, but the template content of vue was not displayed.

just started to learn the project development of webpack+vue, and ran it with webpack-dev-server after configuration, but there was nothing wrong with the page. I"ve been looking for it for two days and I still don"t know why.

here is the code

package.json

{
  "name": "webpack_project2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --open --config webpack.config.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "vue": "^2.5.16"
  },
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-runtime": "^6.26.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "vue-hot-reload-api": "^2.3.0",
    "vue-loader": "^14.2.2",
    "vue-style-loader": "^4.1.0",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^4.4.1",
    "webpack-cli": "^2.0.13",
    "webpack-dev-server": "^3.1.1"
  }
}

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./dist/main.bundle.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
</html>

main.js

import Vue from "vue";
new Vue({
    el:"-sharpapp",
    data:{
        hello:"hello world"
    },
    beforeCreate:function(){
        console.log("beforeCreate")
    },
    created:function(){
        console.log("created")
    },
    beforeMount:function(){
        console.log("beforeMount")
    },
    mounted:function(){
        console.log(this.hello)
    },
    beforeUpdate:function(){
        console.log("beforeUpdate")
    },
    updated:function(){
        console.log("updated")
    },
    template:
        `
        <div>
            

{{hello}}

</div> ` }) console.log("main.js")

webpack.config.js

var path = require("path");

var config = {
    entry:{
        main:"./main.js"
    },
    output:{
        path:path.join(__dirname,"./dist"),
        publicPath:"/dist/",
        filename:"[name].bundle.js"
    },
    module:{
        rules:[
            {
                test:/\.vue$/,
                loader:"vue-loader",
            },
            {
                test:/\.js$/,
                loader:"babel-loader",
                exclude:/node_modules/
            },
            {
                test:/\.css$/,
                loader: "css-loader!style-loader"
            }
        ]
    }
};

module.exports = config;

running result
there is a whiteboard on the

page. There is nothing wrong in the console.

Feb.28,2021

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./dist/main.bundle.js"></script>
    // js -sharpapp   
    //  -sharpapp
</head>
<body>
    <div id="app"></div>
</body>
</html>

may be because the vue runtime version is runtime-only rather than runtime-compiler
runtime-only: code, there cannot be any template
runtime-compiler: code, and there can be template, because compiler can be used to compile template
in the webpack.config.js configuration file, .png

.
Menu