I'm attempting to use Vue at my company. Currently we are not using any Javascript Build tools like Webpack. That means no Babel, (Babel-Standalone also not an option). No Babel means no Template Literals (``), which makes defining Components in purely Javascript files a pain (Internet Explorer does not support Template Literals, and to define Templates in Javascript in clean multiline code, you need Template Literals, and we need IE support). My team has agreed to move towards Laravel and Vue in the near future, but we are working through a server migration and code update before we will be able to properly use Vue.
So I thought I would try to mimic the .vue layout as much as possible. First I create the component in a PHP or HTML file, defining the template in an X-Template along with the Vue component instantiation and styling. In my PHP controller/class/etc. I require the file and it renders in the DOM. This solution works but I have a couple questions.
- Are there any unforeseen issues?
- Is there a way to include the content of these .php/HTML files as Sources rather than being rendered in the DOM?
Example
// MyComponent.php or MyComponent.html
<script type="text/x-template" id="my-component-template">
// component template definition
</script>
<script>
Vue.component('myComponent', {
template: '#my-component-template',
// component vue data/methods/etc
});
</script>
<style>
// component styling
</style>
-
// MyPhpClass.php
public function includeComponents() {
include('path/to/MyComponent.php');
}
-
I've researched quite a bit on using Vue without bundlers. Here's a few of the helpful threads.
- Can we make vue.js application without .vue extension component and webpack?
- A lot of really good information here, but the suggestions focus on using .JS files with Template Literals which is not a possiblility for us
- Vue components without webpack/npm/yarn
- http-vue-loader suggestion seems helpful but I won't be able to use any external libraries outside of Vue