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

The manualInject option doesn't seem to work #40

Open
stigvanbrabant opened this issue Aug 5, 2019 · 1 comment
Open

The manualInject option doesn't seem to work #40

stigvanbrabant opened this issue Aug 5, 2019 · 1 comment

Comments

@stigvanbrabant
Copy link

I'm having trouble using the manualInject option for the vue-style-loader while using vue cli 3.

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Styling keeps automaticly injecting the styling into the DOM

If the current behavior is a bug, please provide the steps to reproduce.

Here is my vue.config.js:

module.exports = {
  parallel: true,
  productionSourceMap: false,
  chainWebpack: (config) => {
    config.resolve.symlinks(false);

    ['vue-modules', 'vue', 'normal-modules', 'normal'].forEach((type) => {
      config.module.rule('scss').oneOf(type).use('vue-style-loader').tap((opt) => {
        opt.manualInject = true;
        return opt;
      });

      config.module.rule('sass').oneOf(type).use('vue-style-loader').tap((opt) => {
        opt.manualInject = true;
        return opt;
      });

      config.module.rule('css').oneOf(type).use('vue-style-loader').tap((opt) => {
        opt.manualInject = true;
        return opt;
      });
    });
  },
};

Inside my main.js

The import:

import styling from './assets/scss/global.scss';

The injection inside my mounting function:

if (styling && styling.__inject__) {
  styling.__inject__();
}

What is the expected behavior?

Ability to manually inject styling by using styling.__inject__().

Please mention other relevant information such as your webpack version, Node.js version and Operating System.

Node version: v10.16.0
OS: Mac OS 10.16.6
Webpack: 4.28.4

@luxel
Copy link

luxel commented Mar 29, 2020

+1 the same issue.

We just used a workaround:

chainWebpack: (config) => {
    // exclude .lazy.css files from default css rules
    config.module.rule('css').exclude.store = [/\.lazy\.css$/]
    config.module
      .rule('lazy-css')
      .test(/\.lazy\.css$/)
      .use('vue-style-loader')
      .loader('vue-style-loader')
      .tap((opt) => {
        if (!opt) {
          opt = { sourceMap: false }
        }
        // turn on shadowMode, so all .lazy.csswill only take effect when __inject__ is called
        opt.shadowMode = true
        return opt
      })
      .end()
      .use('css-loader')
      .loader('css-loader')
      .tap((opt) => {
        if (!opt) {
          opt = { sourceMap: false,
            importLoaders: 2 }
        }
        return opt
      })
      .end()
      .use('postcss-loader')
      .loader('postcss-loader')
      .tap((opt) => {
        if (!opt) {
          opt = { sourceMap: false }
        }
        return opt
      })
      .end()
  }

And in our .vue code, we do this:

import styles from '../assets/field/element-ui/theme/index.lazy.css'
if (styles.__inject__) {
      styles.__inject__(document.body)
    }

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

2 participants