Skip to content

judge isVue from loader options also #13

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

Merged
merged 5 commits into from
Jan 24, 2018
Merged

Conversation

JounQin
Copy link

@JounQin JounQin commented Dec 28, 2017

remainingRequest is string, and can only be used with css-loader?${JSON.stringify(options)}, if we are not using .vue file (jsx in .js file for example), with vue-style-loader?vue we will be able to manually handle styles for ssr also.

// manually
import styles from 'styles.scss'

export default {
  beforeCreate() { // or create a mixin for this purpose
    if(styles.__inject__) {
      styles.__inject__(this.$ssrContext)
    }
  }

  render() {
    return <div class={styles.heading}>Hello World</div>
  }
}



// global mixin example
Vue.mixin({
  beforeCreate() {
    const { styles } = this.$options
    if(styles && styles.__inject__) {
      styles.__inject__(this.$ssrContext)
    }
  }
})


import styles from 'styles.scss'

export default {
  styles,
  render() {
    return <div class={styles.heading}>Hello World</div>
  }
}

Id should be generated via request and resourcePath relative to __dirname, because request is relative to required resource, so if there are same filenames under different folder, it will be same, so I add resourcePath.

And more, vue ssr pattern will be able to use with other js framework!

Example: https://github.com/JounQin/react-hackernews with https://github.com/JounQin/react-style-loader

@JounQin JounQin changed the title judge isVue from loader options alose judge isVue from loader options also Dec 28, 2017
@yyx990803 yyx990803 merged commit cf8f6bd into vuejs:master Jan 24, 2018
@JounQin JounQin deleted the patch-1 branch January 24, 2018 03:57
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.

2 participants