Skip to content

Commit 5b8c06f

Browse files
committed
support plugins config for gsap.registerPlugin
1 parent 03cb541 commit 5b8c06f

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ yarn add nuxt-gsap # or npm install nuxt-gsap
4848
```
4949
## options
5050

51-
You can pass different options using module inline options:
51+
You can pass different options using module inline options, with gsap 3 you probably want to use only plugins:
5252

5353
```js
5454
buildModules: [
5555
'nuxt-gsap', [
5656
{
57-
imports: ['Back', 'Circ'] // Specify the gsap modules you want to import. By default, gsap & Linear are loaded
57+
imports: ['Power2'], // Specify the gsap modules you want to import. By default, gsap is loaded
58+
plugins: ['PixiPlugin', 'ScrollTrigger'] // Various plugins to load, gsap.registerPlugin() will be called on each of them
5859
}
5960
]
6061
]
@@ -67,7 +68,8 @@ or nuxtGsap section in nuxt.config.js
6768
'nuxt-gsap'
6869
],
6970
nuxtGsap: {
70-
imports: ['Back', 'Circ'] // Specify the gsap modules you want to import. By default, gsap & Linear are loaded
71+
imports: ['Power2'], // Specify the gsap modules you want to import. By default, gsap is loaded
72+
plugins: ['PixiPlugin', 'ScrollTrigger'] // Various plugins to load, gsap.registerPlugin() will be called on each of them
7173
}
7274
```
7375

@@ -89,7 +91,7 @@ index.vue
8991
export default {
9092
mounted () {
9193
this.$nextTick(() => { // When using $refs, must wait for nextTick
92-
const tl = this.$gsap.timeline({ repeat: -1, ease: this.$gsap.Linear.easeInOut(2) })
94+
const tl = this.$gsap.timeline({ repeat: -1, ease: this.$gsap.Power2.easeInOut(2) })
9395
tl.to('.test', 2, { x: 200 }) // With css selector
9496
tl.to(this.$refs.test, 0.5, { x: 0 }) // With refs
9597
})

lib/module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module.exports = function gsapNuxtModule (moduleOptions) {
55
...this.options['nuxt-gsap'],
66
...moduleOptions
77
}
8-
const DefaultImports = ['gsap', 'Linear']
8+
const DefaultImports = ['gsap']
99
options.imports = [
1010
...(options.imports || []),
1111
...DefaultImports
12-
].join(', ')
12+
]
1313

1414
this.options.build.transpile.push('gsap')
1515
this.addPlugin({

lib/plugin.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import {<%= options.imports %>} from "gsap"
1+
import {<%= options.imports.join(', ') %>} from "gsap"
22
const activated = [
3-
gsap, <%= options.imports %>
3+
<%= options.imports.join(', ') %>
44
]
5+
<% if (options.plugins) { %>
6+
<% options.plugins.map(p => { %>
7+
import { <%= p %> } from "gsap/<%= p %>.js"
8+
<% }); %>
9+
<% } %>
10+
511
export default async (context, inject) => {
6-
const OptionsObject = {
7-
<%= options.imports %>
12+
<% options.imports.map(i => { %>
13+
gsap[<%= i %>] = <%= i%>
14+
<% }) %>
15+
if (process.client) {
16+
gsap.registerPlugin(<%= options.plugins %>)
817
}
9-
Object.keys(OptionsObject).forEach(key => gsap[key] = OptionsObject[key] )
1018
inject('gsap', gsap)
11-
}
19+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test": "yarn lint && jest"
2121
},
2222
"dependencies": {
23-
"gsap": "^3.2.5"
23+
"gsap": "^3.6.0"
2424
},
2525
"devDependencies": {
2626
"@babel/core": "latest",

0 commit comments

Comments
 (0)