├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── FUNDING.yml ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── example ├── app │ └── sound.config.js ├── nuxt.config.js ├── pages │ ├── index.d.ts │ └── index.vue ├── static │ └── back.wav └── tsconfig.json ├── netlify.toml ├── package.json ├── renovate.json ├── src └── module.ts ├── templates ├── sound.config.js └── sound.js ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .nuxt 4 | coverage 5 | *.log* 6 | .DS_Store 7 | .code 8 | *.iml 9 | package-lock.json 10 | templates/* 11 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@nuxtjs/eslint-config-typescript'], 3 | rules: { 4 | 'space-before-function-paren': false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Tahul] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.iml 3 | .idea 4 | *.log* 5 | .nuxt 6 | .vscode 7 | .DS_Store 8 | coverage 9 | dist 10 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔊 nuxt-use-sound 2 | 3 | This module has been deprecated in favor of [@vueuse/sound/nuxt](https://github.com/vueuse/sound). 4 | 5 | ## License 6 | 7 | [MIT License](./LICENSE) 8 | 9 | ## Credits 10 | 11 | This package comes from [**@vueuse/sound**](https://github.com/vueuse/sound), a package inspired by the React hook, [**useSound**](https://github.com/joshwcomeau/use-sound). 12 | 13 | All the credit behind this idea goes to [**Josh W. Comeau**](https://github.com/joshwcomeau). 14 | -------------------------------------------------------------------------------- /example/app/sound.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | back: { 3 | src: '/back.wav', 4 | options: { 5 | volume: 0.1 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /example/nuxt.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | modules: ['../src/module.ts'], 3 | build: { 4 | extend(config) { 5 | config.module.rules.push({ 6 | test: /\.(ogg|mp3|wav|mpe?g)$/i, 7 | loader: 'file-loader', 8 | options: { 9 | name: '[path][name].[ext]' 10 | } 11 | }) 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/pages/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.wav' 2 | -------------------------------------------------------------------------------- /example/pages/index.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /example/static/back.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tahul/nuxt-use-sound/c46bd9be7cdcac95f9d6363ece61273a0826204e/example/static/back.wav -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | # Global settings applied to the whole site. 2 | # 3 | # “base” is the directory to change to before starting build. If you set base: 4 | # that is where we will look for package.json/.nvmrc/etc, not repo root! 5 | # “command” is your build command. 6 | # “publish” is the directory to publish (relative to the root of your repo). 7 | 8 | [build] 9 | base = "docs" 10 | command = "yarn && yarn generate" 11 | publish = "dist" 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt-use-sound", 3 | "version": "1.0.8", 4 | "description": "🔊 A Nuxt module for playing sound effects.", 5 | "keywords": [ 6 | "nuxt", 7 | "module", 8 | "nuxt-module", 9 | "vue", 10 | "use", 11 | "sound", 12 | "composable" 13 | ], 14 | "repository": "https://github.com/Tahul/nuxt-use-sound", 15 | "license": "MIT", 16 | "author": { 17 | "name": "Yaël GUILLOUX", 18 | "email": "yael.guilloux@gmail.com" 19 | }, 20 | "main": "dist/module.js", 21 | "types": "dist/module.d.ts", 22 | "files": [ 23 | "dist", 24 | "templates" 25 | ], 26 | "scripts": { 27 | "build": "siroc build", 28 | "dev": "nuxt example", 29 | "lint": "eslint --ext .js,.ts,.vue .", 30 | "release": "yarn build && yarn test && standard-version && git push --follow-tags && npm publish" 31 | }, 32 | "dependencies": { 33 | "@nuxtjs/composition-api": "^0.20.2", 34 | "@vueuse/sound": "latest", 35 | "defu": "^3.2.2", 36 | "vue-demi": "^0.6.1" 37 | }, 38 | "devDependencies": { 39 | "@babel/plugin-transform-runtime": "latest", 40 | "@babel/preset-env": "latest", 41 | "@babel/preset-typescript": "latest", 42 | "@nuxt/test-utils": "latest", 43 | "@nuxt/types": "latest", 44 | "@nuxt/typescript-runtime": "latest", 45 | "@nuxtjs/eslint-config-typescript": "latest", 46 | "babel-eslint": "latest", 47 | "eslint": "latest", 48 | "nuxt-edge": "latest", 49 | "siroc": "latest", 50 | "standard-version": "latest" 51 | }, 52 | "publishConfig": { 53 | "access": "public" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/module.ts: -------------------------------------------------------------------------------- 1 | import type { Module } from '@nuxt/types' 2 | import type { 3 | ComposableOptions, 4 | ReturnedValue 5 | } from '@vueuse/sound/dist/esm/src/types' 6 | import defu from 'defu' 7 | import { resolve } from 'path' 8 | 9 | export type Sound = { 10 | src: string 11 | options: ComposableOptions 12 | } 13 | 14 | export interface ModuleOptions { 15 | [K: string]: Sound 16 | } 17 | 18 | const DEFAULTS: ModuleOptions = {} 19 | 20 | const CONFIG_KEY = 'sound' 21 | 22 | const nuxtModule: Module = async function(moduleOptions) { 23 | const options: ModuleOptions = defu( 24 | this.options[CONFIG_KEY]!, 25 | moduleOptions, 26 | DEFAULTS 27 | ) 28 | 29 | this.addTemplate({ 30 | fileName: 'sound.config.js', 31 | src: resolve(__dirname, '../templates', 'sound.config.js') 32 | }) 33 | 34 | this.addPlugin({ 35 | src: resolve(__dirname, '../templates', 'sound.js'), 36 | fileName: 'sound.js', 37 | options 38 | }) 39 | 40 | this.nuxt.options.build.transpile.push('defu') 41 | 42 | await this.addModule('@nuxtjs/composition-api') 43 | } 44 | 45 | ;(nuxtModule as any).meta = require('../package.json') 46 | 47 | declare module '@nuxt/types' { 48 | interface NuxtConfig { 49 | [CONFIG_KEY]?: ModuleOptions 50 | } // Nuxt 2.14+ 51 | interface Configuration { 52 | [CONFIG_KEY]?: ModuleOptions 53 | } // Nuxt 2.9 - 2.13 54 | interface Context { 55 | $sounds: { 56 | [K: string]: ReturnedValue 57 | } 58 | } 59 | } 60 | 61 | export default nuxtModule 62 | -------------------------------------------------------------------------------- /templates/sound.config.js: -------------------------------------------------------------------------------- 1 | export default {} 2 | -------------------------------------------------------------------------------- /templates/sound.js: -------------------------------------------------------------------------------- 1 | import { useSound } from '@vueuse/sound' 2 | import defu from 'defu' 3 | import appOptions from './sound.config' 4 | 5 | const options = defu(appOptions, <%= JSON.stringify(options, null, 2) %>) 6 | 7 | /** 8 | * @type {import('@nuxt/types').Plugin} 9 | */ 10 | export default async ({ app }, inject) => { 11 | 12 | const $sounds = {} 13 | 14 | app.setup = (_, ctx) => { 15 | for (const sound of Object.entries(options)) { 16 | $sounds[sound[0]] = useSound( 17 | sound[1].src, 18 | sound[1].options ? sound[1].options : {} 19 | ) 20 | } 21 | } 22 | 23 | inject('sounds', $sounds) 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "es2018", 5 | "module": "esnext", 6 | "lib": ["esnext", "dom"], 7 | "esModuleInterop": true, 8 | "moduleResolution": "node", 9 | "declaration": false, 10 | "skipLibCheck": true, 11 | "resolveJsonModule": true, 12 | "allowSyntheticDefaultImports": true, 13 | "types": ["node"] 14 | }, 15 | "exclude": ["node_modules", "dist"] 16 | } 17 | --------------------------------------------------------------------------------