How to add vue.js to existing webpack project?

by mallory_cormier , in category: Javascript , 8 months ago

How to add vue.js to existing webpack project?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 8 months ago

@mallory_cormier 

To add Vue.js to an existing webpack project, you can follow these steps:

  1. Install Vue.js using npm:
1
npm install vue


  1. Update your webpack.config.js file to include Vue.js as an entry point:
1
2
3
4
5
6
7
module.exports = {
  entry: {
    app: './src/index.js',
    vue: 'vue'
  },
  // rest of your webpack configuration
}


  1. Update your index.js file (or main entry file) to include Vue:
1
2
3
4
5
6
import Vue from 'vue';
import App from './App.vue';

new Vue({
  render: h => h(App)
}).$mount('#app');


  1. Create a new Vue component in your project (e.g. App.vue):
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<template>
  <div>
    <h1>Hello, Vue.js!</h1>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style>
/* Add your styles here */
</style>


  1. Build your project using webpack:
1
webpack


  1. Include the bundled JavaScript file in your HTML file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<!DOCTYPE html>
<html>
<head>
  <title>Vue.js App</title>
</head>
<body>
  <div id="app"></div>
  <script src="dist/bundle.js"></script>
</body>
</html>


After following these steps, you should have successfully added Vue.js to your existing webpack project. You can now start creating Vue components and building your application using Vue.js.