ktsn / vue-template-loader

Vue.js 2.0 template loader for webpack
MIT License
266 stars 26 forks source link

Add options for base styles path #37

Closed CKGrafico closed 7 years ago

CKGrafico commented 7 years ago

The improvement is to change your flow from relative folder to file name if you want:

before:

{
        test: /\.html$/,
        loader: 'vue-template-loader',
        options: {
            scoped: true
        }
    }
import { Component, Vue } from 'vue-property-decorator';

import Template from './app.component.html?style=../../dist/css/scripts/app.component.css';

@Template
@Component
export class AppComponent extends Vue {
}

after:

{
        test: /\.html$/,
        loader: 'vue-template-loader',
        options: {
            scoped: true,
            stylesFolder: '../../dist/css/scripts/'
        }
    }
import { Component, Vue } from 'vue-property-decorator';

import Template from './app.component.html?style=app.component.css';

@Template
@Component
export class AppComponent extends Vue {
}

Why? Sometimes you don't want to compile your style preprocesor with webpack and you have all the files compiled separately, this with help also on other workflows.

CKGrafico commented 7 years ago

Suggestion, As I told on an issue, I don't like the queryparemeters flow but I think this is the smallest change that I can suggest.

Another suggestion is to generate the .css file from .html name but maybe is too magic.

CKGrafico commented 7 years ago

Another way to solve that (probably better) is to add a option to use the same folder for .html and .css I can implement it if you want

ktsn commented 7 years ago

Thanks for your PR. However I'm not a fan of adding a feature that we already achieve with a webpack feature. In your case, you can set resolve.modules option in webpack config.

module.exports = {
  resolve: {
    modules: [
      path.resolve('/path/to/css'),
      'node_modules'
    ]
  }
}
CKGrafico commented 7 years ago

Thank you're right, now we have:

modules: [
                path.resolve(__dirname, 'dist/css/scripts'),
                'node_modules'
            ],

app.component.ts

import Template from './app.component.html?style=app.component.css';

but for children

import Template from './city-list.component.html?style=cities/city-list/city-list.component.css';

Not sure if we can resolve all the children folders with one resolve

ktsn commented 7 years ago

Hmm, in that case, you should copy all js/html files to dist directory in build time? I think it would be the easiest solution than hacking webpack config.