Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 54bc6cf

Browse files
committed
🌭 feat: add audio and video pages
1 parent a26d648 commit 54bc6cf

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

nuxt.config.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ const config: NuxtConfiguration = {
3535
// https://ja.nuxtjs.org/api/configuration-build/#devtools
3636
devtools: true,
3737

38+
loaders: {
39+
// https://ja.nuxtjs.org/faq/webpack-audio-files/
40+
vue: {
41+
// 特殊なアトリビュートでも webpack の require がかまされるようにする
42+
transformAssetUrls: {
43+
audio: 'src',
44+
video: ['src', 'poster'],
45+
source: 'src',
46+
img: ['src', 'data-src'],
47+
'lazy-image': 'src'
48+
}
49+
}
50+
},
51+
3852
/**
3953
* You can extend webpack config here
4054
*/
@@ -59,18 +73,14 @@ const config: NuxtConfiguration = {
5973
}
6074
}
6175

62-
const vueLoader: any = config.module!.rules.find(
63-
(rule): boolean => rule.loader === 'vue-loader'
64-
)
65-
// 特殊なアトリビュートでも webpack の require がかまされるようにする
66-
vueLoader.options.transformAssetUrls = {
67-
video: ['src', 'poster'],
68-
source: 'src',
69-
img: ['src', 'data-src'],
70-
image: 'xlink:href',
71-
Test: 'source',
72-
'lazy-image': 'src'
73-
}
76+
// https://ja.nuxtjs.org/faq/webpack-audio-files/
77+
config.module!.rules.push({
78+
test: /\.(ogg|mp3|wav|mpe?g)$/i,
79+
loader: 'file-loader',
80+
options: {
81+
name: '[path][name].[ext]'
82+
}
83+
})
7484
},
7585
extractCSS: isProduction,
7686

src/assets/audio/menuettm.mp3

2.1 MB
Binary file not shown.

src/assets/video/bump.mp4

7.55 MB
Binary file not shown.

src/pages/example/audio.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template lang="pug">
2+
section
3+
h1.title
4+
| audio
5+
p
6+
audio(src="~/assets/audio/menuettm.mp3", autoplay, controls)
7+
8+
// ChromeとSafariでaudioタグを自動再生するための対策 │ Webty Staff Blog - https://webty.jp/staffblog/production/post-907/
9+
iframe#audio(src='https://raw.githubusercontent.com/anars/blank-audio/master/500-milliseconds-of-silence.mp3', allow='autoplay', style='display:none')
10+
</template>
11+
12+
<script lang="ts">
13+
import { Component, Vue } from 'nuxt-property-decorator'
14+
15+
@Component
16+
export default class Audio extends Vue {
17+
public head() {
18+
return {
19+
title: 'audio'
20+
}
21+
}
22+
}
23+
</script>
24+
25+
<style lang="scss" scoped>
26+
h2 {
27+
color: crimson;
28+
}
29+
</style>

src/pages/example/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ section
5959
nuxt-link(to='/example/v-scroll') v-scroll
6060
p
6161
nuxt-link(to='/example/vue-awesome-swiper') vue-awesome-swiper
62+
p
63+
nuxt-link(to='/example/audio', no-prefetch) audio
64+
p
65+
nuxt-link(to='/example/video', no-prefetch) video
6266
</template>
6367

6468
<script lang="ts">

src/pages/example/video.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<template lang="pug">
2+
section
3+
h1.title
4+
| video
5+
p
6+
video(src="@/assets/video/bump.mp4", width="500", autoplay, controls)
7+
8+
// ChromeとSafariでaudioタグを自動再生するための対策 │ Webty Staff Blog - https://webty.jp/staffblog/production/post-907/
9+
iframe#audio(src='https://raw.githubusercontent.com/anars/blank-audio/master/500-milliseconds-of-silence.mp3', allow='autoplay', style='display:none')
10+
</template>
11+
12+
<script lang="ts">
13+
import { Component, Vue } from 'nuxt-property-decorator'
14+
15+
@Component
16+
export default class Audio extends Vue {
17+
public head() {
18+
return {
19+
title: 'video'
20+
}
21+
}
22+
}
23+
</script>
24+
25+
<style lang="scss" scoped>
26+
h2 {
27+
color: crimson;
28+
}
29+
</style>

0 commit comments

Comments
 (0)