Skip to content

Add Vue.js support #1189

Open
Open
@michaelw85

Description

@michaelw85

As the title explains, it would be nice to have a vue: true option instead of having to manually configure it.

I've got a manual setup working for Vue + TS (with class component and .vue files support) and the following was needed:

NPM:
npm i -D vue vue-template-compiler vue-loader vue-class-component ts-loader babel-preset-typescript-vue @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties

wpackio.project.js:

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

module.exports = {
      files: [
        {
            name: "xyz",
            entry: {},
            webpackConfig: {
                module: {
                    rules: [
                        {
                            test: /\.vue$/,
                            loader: "vue-loader",
                            options: {
                                esModule: true,
                            },
                        },
                        {
                            test: /\.ts$/,
                            loader: "ts-loader",
                            options: {
                                appendTsSuffixTo: [/\.vue$/],
                            },
                        },
                    ],
                },
                plugins: [new VueLoaderPlugin()],
            },
        },
....
    tsBabelOverride: (defaults) => ({
        ...defaults,
        presets: ["babel-preset-typescript-vue"],
        plugins: [
            ["@babel/proposal-decorators", { legacy: true }],
            ["@babel/proposal-class-properties", { loose: true }],
        ],
    }),
...
    alias: {
        vue$: "vue/dist/vue.esm.js",
    },

Add a vue-shim.d.ts to your typings folder:

declare module "*.vue" {
    import Vue from "vue";
    export default Vue;
}

Make sure your typings are loaded in your tsconfig.json, something like:
"typeRoots": ["node_modules/@types", "typings"]

For a working example using a child theme see: https://github.com/michaelw85/wp-bedrock-wpack-vuejs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions