Skip to content

Commit

Permalink
fix: add script to webpack build (in dev) for storybook support (#99)
Browse files Browse the repository at this point in the history
* closes #69

Co-authored-by: Sébastien Chopin <[email protected]>
  • Loading branch information
danielroe and atinux authored Aug 2, 2021
1 parent c58d47a commit 54b482b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { join, resolve } from 'path'
import { promises as fsp } from 'fs'
import crypto from 'crypto'
import defu from 'defu'
Expand Down Expand Up @@ -43,6 +43,18 @@ export default async function (moduleOptions) {
head[serializeProp][options.hid] = ['innerHTML']
})


// In dev mode we also inject full script via webpack entrypoint for storybook compatibility
if (this.nuxt.options.dev) {
const { dst } = this.addTemplate({ src: resolve(__dirname, 'script.js'), fileName: join('color-mode', 'script.js'), options })
this.nuxt.hook('webpack:config', (configs) => {
for (const config of configs) {
if (config.name !== 'server') {
config.entry.app.unshift(resolve(this.nuxt.options.buildDir, dst))
}
}
})
}
this.nuxt.hook('vue-renderer:ssr:csp', (cspScriptSrcHashes) => {
const { csp } = this.options.render
const hash = crypto.createHash(csp.hashAlgorithm)
Expand Down

0 comments on commit 54b482b

Please sign in to comment.