1

When I use Vue in an HTML file like below, it works fine.

<body>
<div id="app">
  <!-- something in here -->
</div>
<script>
new Vue({
  el: "#app",
  data: function() {
  }
  //and so on ....
})
</script>
</body>

But When I use webpack to build it. The output js file which I put in HTML header does not parse the HTML correctly. And seems Vue.js is not working.

Here are my webpack config file and entry js file.

/**
 * webpack.config.js
 */
const path = require('path');

module.exports = {
    entry: './src/index.js',
    output:{
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    module:{
        rules:[
            {
                test: /\.css$/,
                use:[
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.(png|svg|jpg|gif|ico)$/,
                use:[
                    'file-loader'
                ]
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use:[
                    'file-loader'
                ]
            }
        ]
    }
}
/**
 * index.js (the entry js file)
 */
import axios from "axios";
import Vue from "vue";

var baseUrl = "/activity/gqzq/AjaxGetList";

var vm = new Vue({
  el: "#app",
  data: function() {},
  //...... 
})

My question is, Why the output file is not working? And how to make it right?

1 Answer 1

2

Just use the proper official tools, all the Webpack is configured for you.

https://cli.vuejs.org/

Sign up to request clarification or add additional context in comments.

2 Comments

I know I can use cli, But I want to know which part did I do wrong
Missing vue-loader, vue-loader/lib/plugin, devServer and many other things in webpack.config.js Create a project by vue-cli and compare what you are missing is the best way to learn.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.