activewidgets / getlibs

OBSOLETE, DO NOT USE: This project is no longer maintained
MIT License
165 stars 12 forks source link

ES6 module exports on .vue files #1

Closed sylvainpolletvillard closed 7 years ago

sylvainpolletvillard commented 7 years ago

Hello and thank you for making this, it looks very promising.

I tried getlibs on a Vue + TypeScript project and got some trouble with single file components .vue files

index.html:

<!DOCTYPE html>
<html>
<head>
    <script src="https://unpkg.com/getlibs"></script>
</head>
<body>
<div id="app">Loading...</div>

<script>
    System.import('./main.ts')
</script>
</body>
</html>

main.ts:

import Vue from 'vue'
import App from './components/App.vue'

new Vue({
    el: '#app',
    render: h => h(App)
})

App.vue:

<template>
    <div id="app">
        Hello {{ name }}
    </div>
</template>

<script>
    export default {
        data(){
            return { name: "Vue" }
        }
    }
</script>

gives me

Error: module is not defined
  Evaluating http://localhost:5000/components/App.vue
  Evaluating http://localhost:5000/main.ts
  Loading ./main.ts`

The App.vue!transpiled file :

(function(System, SystemJS) {"use strict";

System.register([], function (_export, _context) {
    "use strict";

    return {
        setters: [],
        execute: function () {
            _export("default", {
                data: function data() {
                    return { name: "Vue" };
                }
            });

            module.exports.template = "\r\n\t<div id=\"app\">\r\n\t\tHello {{ name }}\r\n\t</div>\r\n";
        }
    };
});
})(System, System);

It looks like it should export with _export.template instead of module.exports.template

xkam commented 7 years ago

At the moment .vue loader works only with es5/require() syntax. Basically it just tries to inject the template property into module.exports object. I'll see if I can do something simple for es6/typescript.

xkam commented 7 years ago

I've changed .vue loader so ES6 import/export should work now. However it will be transpiled by babel instead of typescript at the moment. That I still have to fix.

sylvainpolletvillard commented 7 years ago

Thanks, I can confirm that it is now working with export default. I let you close this issue when you are done

sylvainpolletvillard commented 7 years ago

Not sure if it is a regression or if it is not supported at the moment, but the <style> tags in the .vue files do not work.

xkam commented 7 years ago

This is a regression - will fix in the next release.

xkam commented 7 years ago

styles should work now in 0.0.11 (global only, scoped styles not supported yet).

xkam commented 7 years ago

.vue components are now transpiled by typescript (in .ts context). Added support for class-style components and decorators - https://github.com/activewidgets/getlibs-vue-hello-ts

sylvainpolletvillard commented 7 years ago

Excellent work ! I will definitely use this