Skip to content

VueLoaderPlugin causes loaders to run several times #1278

Closed
@killerDJO

Description

@killerDJO

Version

15.0.0

Reproduction link

https://github.com/killerDJO/vue-loader-minimal

Steps to reproduce

Prererquisites:

  • ts-loader is used and has options specified (Important!).
  • SFC with referenced TypeScript file is used.

Run webpack build using mentioned configuration. Rules might look like this:

module: {
    rules: [
        {
            test: /\.ts$/,
            loader: "ts-loader",
            options: {},
            exclude: [/node_modules/]
        },
        {
            test: /\.vue$/,
            loader: "vue-loader",
        }
    ]
},
resolve: {
    extensions: [".ts"],
},
plugins: [
    new VueLoaderPlugin()
],

What is expected?

Build is finished successfully.

What is actually happening?

Build failed.


In the current implementation VueLoaderPlugin clones webpack rules and modifies them to run on .vue files. However, this leads to an issues when a file is referenced from .vue component (e. g. <script src="./App.ts" lang="ts"></script>). In this case the file can be matched by two rules (original and cloned) and ts-loader will be executed two times, with second time executing using output of the first run.
This will happend only if "options" object is specified, because otherwise webpack will use a single loader for two rules (VueLoaderPlugin removes "options" during rules cloning, so only original rule will have options).

Aforementioned behaviour has been observed for ts-loader, but is likely to occur for scss/sass loaders as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions