Skip to content

Commit

Permalink
fix: nuxt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jan 18, 2020
1 parent 29ee2d2 commit e612a35
Show file tree
Hide file tree
Showing 8 changed files with 7,336 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.nuxt
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ import { StyledVue } from 'styled-vue'
Vue.use(StyledVue)
```

<small>For Nuxt users we automatically register it for you.</small>

This only adds ~100 bytes to your application.

### TypeScript
Expand Down
3 changes: 3 additions & 0 deletions examples/nuxt/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
modules: ['styled-vue/nuxt']
}
10 changes: 10 additions & 0 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "nuxt",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"nuxt": "^2.11.0",
"styled-vue": "^0.3.1"
}
}
37 changes: 37 additions & 0 deletions examples/nuxt/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div>
<h1>Hello Nuxt</h1>
<h2>And hello styled-vue</h2>
<p>This is awesome!</p>
</div>
</template>

<script>
import { css } from 'styled-vue'
export default {
style: css`
h1 {
color: red;
}
h2 {
font-style: italic;
}
p {
color: #999;
}
`,
globalStyle: css`
body {
background: ${vm => vm.bg};
}
`,
data() {
return {
bg: 'cyan'
}
}
}
</script>

<style></style>
7,271 changes: 7,271 additions & 0 deletions examples/nuxt/yarn.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions nuxt/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module.exports = function() {
const path = require('path')

module.exports = function({ registerStyledVue = true } = {}) {
// Lazy load compiler on build only
this.nuxt.hook('build:before', () => {
const { vue } = this.options.build.loaders
if (!vue.compiler) {
vue.compiler = require('../lib/compiler')
}
vue.compiler = require('../lib/compiler')
})

if (registerStyledVue) {
this.addPlugin(path.join(__dirname, 'plugin.js'))
}
}
4 changes: 4 additions & 0 deletions nuxt/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Vue from 'vue'
import { StyledVue } from '../lib'

Vue.use(StyledVue)

0 comments on commit e612a35

Please sign in to comment.