Skip to content

Support for default file names for file type separation. #1392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ZSkycat opened this issue Aug 27, 2018 · 0 comments
Open

Support for default file names for file type separation. #1392

ZSkycat opened this issue Aug 27, 2018 · 0 comments

Comments

@ZSkycat
Copy link

ZSkycat commented Aug 27, 2018

What problem does this feature solve?

In order to get the typescript language service and the extended full service, the vue component is written in a separate file type. It is cumbersome to specify the name of src every time. Renaming files can also cause cumbersome.

// file: ./View.vue
<template>
    <div>......</div>
</template>
<script src="./View.ts"></script>
<style src="./View.css"></style>

Allow vue-loader to specify the default src rule. For example
When the script does not exist in the .vue file, it searches for the existence of the file according to the rule. If it exists, it is used. If it does not exist, it is not used.

{
    test: /\.vue$/,
    use: [
        { loader: 'vue-loader', options: { defaultScriptSrc: './[name].ts', defaultStyleSrc: './[name].css' } },
    ],
},

为了获得 typescript 的语言服务和扩展的完整服务,采用文件类型分离的方式编写 vue 组件。每次都需要指定 src 的名称是一件很繁琐的事情。重命名文件也会带来麻烦。

// file: ./View.vue
<template>
    <div>......</div>
</template>
<script src="./View.ts"></script>
<style src="./View.css"></style>

允许 vue-loader 指定默认的 src 规则。例如
当 .vue 文件不存在 script 时,按规则查找文件是否存在,若存在则使用,不存在则不使用。

{
    test: /\.vue$/,
    use: [
        { loader: 'vue-loader', options: {
            defaultScriptSrc: './[name].ts',
            defaultStyleSrc: './[name].css' }
        },
    ],
},

What does the proposed API look like?

Options

defaultTemplateSrc

type: string | string[] | false
default: false

defaultScriptSrc

type: string | string[] | false
default: false

defaultStyleSrc

type: string | string[] | false
default: false

Use [name] to indicate the file name
example:

'./[name].ts'
['./[name].ts', './[name].tsx']

Related issues

#1281
vuejs/vetur#188 (comment)
vuejs/vetur#188 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant