Parcel: Vue SFC code splitting

Created on 9 May 2018  ยท  5Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ™‹ feature request

I would like to be able to split a Vue Single File Component (SFC) into separate files:

  • Template
  • Script
  • Style

This is briefly documented here: What About Separation of Concerns?

๐Ÿค” Expected Behavior

The script/style file should be built by Parcel.

๐Ÿ˜ฏ Current Behavior

I have tried the method documented on the link above, but the script/style file is not built by Parcel, and it is not included in the output.

๐Ÿ’ Possible Solution

I believe the solution is either obvious or someone will know better than I do.

When a script tag has a src attribute, then the script file (JavaScript, TypeScript, etc) should be built by Parcel. I am not sure if the embedded script should be ignored in this case.

When a style tag has a src attribute, then the style file (CSS, LESS, SASS/SCSS, etc) should be built by Parcel. I am not sure if the embedded styles should be ignored in this case.

๐Ÿ”ฆ Context

I started using Parcel, Vue.js and vue-router recently, and I organize my Vue components as Single File Components (SFC) with the template, script and styles in these *.vue files due to its simplicity. I do not know the best practices, but as some of my *.vue files are growing in length, I find it more inconvenient to navigate between the template/script/style sections.

I also see no reason to not support this feature because it is documented usage of Vue.js.

If there are no good alternatives, then I also see no reason to not support this feature, because separation is oftentimes a good thing.

Different people can work on the template, script and styles without also crossing the other "layers".

๐Ÿ’ป Examples

Taken from What About Separation of Concerns?:

<!-- my-component.vue -->
<template>
  <div>This will be pre-compiled</div>
</template>
<script src="./my-component.js"></script>
<style src="./my-component.css"></style>

my-component.vue contains mostly the template; ./my-component.js contains the script; ./my-component.css contains the styles.

Feature Vue โœจ Parcel 2

Most helpful comment

It's been the better part of a year since this was first posted. Is there any update on this?

By the way, a slight simpler way writing what's mentioned above is:

<script>
  export {default} from './script.js';
</script>

All 5 comments

Another bad thing about .vue files is that it break a lot of tooling, for example certain functions of intelisense in VScode. For anyone who want a solution now, you can do something like this.

<script>
  import MyComponentScript from './my-component-script.js'
  export default MyComponentScript 
</script>
<style lang="scss">
  @import './my-component-style.scss';
</style >
<templatelang="pug">
  include my-component-template.pug
</template>

It's been the better part of a year since this was first posted. Is there any update on this?

By the way, a slight simpler way writing what's mentioned above is:

<script>
  export {default} from './script.js';
</script>

Any solution on this? i'm having the same issue

Any update on this?
I am trying to setup my project using vue and I was very surprised that

<style src="./app.scss" lang="scss"></style>

doesn't work in my App.vue file :-/

This is part of the Vue documentation and Webpack does support it, so why doesn't Parcel support it?
Also, I really do think that a warning about this has to be written on the vue section of the parcel website, as I searched for hours before finding this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnn picture mnn  ยท  3Comments

philipodev picture philipodev  ยท  3Comments

davidnagli picture davidnagli  ยท  3Comments

devongovett picture devongovett  ยท  3Comments

davidnagli picture davidnagli  ยท  3Comments