DEV Community

Mark
Mark

Posted on • Edited on

How to create a Vue3 Application with Webpack - JavaScript Version

In this article, let's create a Vue3 template project, it involves Vue3, Webpack.

https://github.com/markliu2013/vue3-template-js

Create a folder and initialize NPM

npm init -y
Enter fullscreen mode Exit fullscreen mode

Install Vue3

npm i vue
Enter fullscreen mode Exit fullscreen mode

Install Webpack

npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin
Enter fullscreen mode Exit fullscreen mode

Create src folder and index.html, App.vue, main.js

Install babel-loader

npm i -D @babel/core @babel/preset-env babel-loader
Enter fullscreen mode Exit fullscreen mode

Create file babel.config.json

{
  "presets": [
    "@babel/preset-env"
  ]
}

Enter fullscreen mode Exit fullscreen mode

Install vue-loader

npm i -D vue-loader
Enter fullscreen mode Exit fullscreen mode

Create file webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {VueLoaderPlugin} = require("vue-loader");

module.exports = {
    mode: "production",
    devtool: "source-map",
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].chunk.js',
        clean: true
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'src/index.html' // to import index.html file inside index.js
        }),
        new VueLoaderPlugin(),
    ],
    devServer: {
        port: 3039 // you can change the port
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                exclude: /node_modules/,
                use: {
                    loader: 'vue-loader',
                }
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                }
            },
        ]
    },
};
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay