Skip to content

Integration with VueJS + Typescript possible ? #113

@lodacom

Description

@lodacom

I tried to integrate Ara Framework with Typescript and VueJs. My project comes with my own external library.
Here is my webpack config :

const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const NodemonPlugin = require('nodemon-webpack-plugin');

const server = {
    target: 'node',
    entry: path.join(__dirname, 'src/server.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'fournisseur-app-server.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    presets: ['@babel/preset-env',{
                        'plugins': ['@babel/plugin-proposal-class-properties']}]
                }
            },
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/],
                }
            },
            {
                test: /\.vue$/,
                exclude: /node_modules/,
                loader: 'vue-loader'
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                loader: 'file-loader'
            },
            {
                test: /\.(eot|fsvg|ttf|otf|woff|woff2)$/,
                loader: 'url-loader',
                options: {
                    name: '[name].[ext]',
                    publicPath: 'fonts'
                }
            },
            {
                test: /\.css$/,
                use: [
                    'vue-style-loader',
                    'css-loader'
                ]
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new NodemonPlugin()
    ],
    resolve: {
        extensions: ['.ts', '.js', '.vue'],
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        }
    }
}

const client = {
    target: 'web',
    node: {
        fs: 'empty',
        module: 'empty'
    },
    entry: path.join(__dirname, 'src/client.js'),
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'fournisseur-app-client.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    presets: ['@babel/preset-env',{
                        'plugins': ['@babel/plugin-proposal-class-properties']}]
                }
            },
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/],
                }
            },
            {
                test: /\.vue$/,
                exclude: /node_modules/,
                loader: 'vue-loader'
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                loader: 'file-loader'
            },
            {
                test: /\.(eot|fsvg|ttf|otf|woff|woff2)$/,
                loader: 'url-loader',
                options: {
                    name: '[name].[ext]',
                    publicPath: 'fonts'
                }
            },
            {
                test: /\.css$/,
                use: [
                    'vue-style-loader',
                    'css-loader'
                ]
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin()
    ],
    resolve: {
        extensions: ['.ts', '.js', '.vue'],
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        }
    }
};

module.exports = [server, client];

When I launch my Ara dev task ("ara:dev": "webpack --config araWebpack.config.js --watch --mode development"), it's crashed with this mysterious error :

webpack:///./node_modules/vue/dist/vue.esm.js?:9227
decoder = decoder || document.createElement('div');
^

ReferenceError: document is not defined
at decode (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:9227:26)
at cachedFn (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:163:33)
at Object.chars (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:9865:50)
at parseHTML (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:9388:17)
at parse (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:9731:3)
at baseCompile (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:11855:13)
at compile (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:11830:22)
at Function.compileToFunctions [as compile] (webpack:///./node_modules/←[4mvue←[24m/dist/vue.esm.js?:11713:20)

When I comment the server part in webpack config, client part is generated whithout any issue.

Here is my client.js :

import {Vue, renderVue} from 'hypernova-vue';

import Fournisseur from './components/Fournisseur';

import BootstrapVue from 'bootstrap-vue/dist/bootstrap-vue.esm';

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css';

Vue.use(BootstrapVue);

document.addEventListener('NovaMount', (event) => {
    const { detail: { name } } = event
    switch (name) {
        case 'Fournisseur' :
            return renderVue(name, Vue.extend(Fournisseur));
    }
});

And here is my server.js :

import hypernova from 'hypernova/server';
import {renderVue, Vue} from 'hypernova-vue/server';
import express from 'express';
import path from 'path';

import BootstrapVue from 'bootstrap-vue/dist/bootstrap-vue.esm';

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css';

import Fournisseur from './components/molecule/Fournisseur';

Vue.use(BootstrapVue);

hypernova({
    devMode: process.env.NODE_ENV !== 'production',
    getComponent(name) {
        switch (name) {
            case 'Fournisseur' :
                return renderVue(name, Vue.extend(Fournisseur));
        }
    },

    port: process.env.PORT || 3001,

    createApplication() {
        const app = express();

        app.use('/public', express.static(path.join(process.cwd(), 'dist')));

        return app;
    }
});

It's seem that the issue is coming from my external library. Like the latter was interpreted twice. I tried to exclude it, but without any effect.
Have you any idea to force this behaviour or to solve this kind of issue in Ara environnement ?

I specify that I didn't encounter this issue when I launch my server without Ara things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions