Skip to content
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

Allow "layer" and "issuerLayer" rule properties #1809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevethedev
Copy link

The "layer" and "issuerLayer" rules are useful experimental properties that are currently stripped out by the Vue Loader plugin. This change fixes that issue.

My specific use-case was to load SVG files as Vue components if they are imported into a script, but import them as URLs if I reference them in the CSS. Layers make this trivial:

module.exports = {
  experiments: { layers: true },
  module: {
    rules: [
      { test: /\.vue$/, loader: "vue-loader" },
      { test: /\.vue$/, resourceQuery: /type=script/, layer: "script" },
      { test: /\.[jt]s$/, layer: "script" },
      {
        test: /\.svg$/i,
        oneOf: [
          { loader: 'vue-svg-loader', issuerLayer: "script" },
          { loader: 'file-loader' },
        ],
      },
    ],
  }
};

The "layer" and "issuerLayer" rules are useful experimental properties that are currently stripped out by the Vue Loader plugin. This change fixes that issue.

My specific use-case was to load SVG files as Vue components if they are imported into a script, but import them as URLs if I reference them in the CSS. Layers make this trivial:

```
module.exports = {
  experiments: { layers: true },
  module: {
    rules: [
      { test: /\.vue$/, loader: "vue-loader" },
      { test: /\.vue$/, resourceQuery: /type=script/, layer: "script" },
      { test: /\.[jt]s$/, layer: "script" },
      {
        test: /\.svg$/i,
        oneOf: [
          { loader: 'vue-svg-loader', issuerLayer: "script" },
          { loader: 'file-loader' },
        ],
      },
    ],
  }
};
```
@mrleblanc101
Copy link

mrleblanc101 commented Aug 23, 2021

Will this work in webpack 4 ? I'm trying to do something similar in Nuxt.
The problem is that layer and issueLayer do not exist in webpack 4, only resourceQuery.

config.module.rules.push({
    test: /\.svg$/,
    resourceQuery: /script/,
    use: ['babel-loader',
    'vue-svg-loader']
});

I couldnt' figure out why it's not working but when I look into the bundle code, there is no ?vue&type=script so I think that's why my resourceQuery does nothing.
__webpack_require__(/*! @/assets/svg/placeholder/organismes.svg*/ \"./src/assets/svg/placeholder/organismes.svg\")
should be __webpack_require__(/*! @/assets/svg/placeholder/organismes.svg?vue&type=script*/ \"./src/assets/svg/placeholder/organismes.svg?vue&type=script\") I think for this to work.
I hope this fix will add these attributes back so that resourceQuery will work in Webpack 4

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

Successfully merging this pull request may close these issues.

None yet

2 participants