目次
共通scssファイルを使いたい場合の設定
3つのライブラリをインストール
$ npm install node-sass
$ npm install sass-loader
$ npm install @nuxtjs/style-resources
サンプルとしてvariable.scssを用意
$base-color :#CEE3F6;
nuxt.config.jsの編集
modules: [
],
上記のmodulesの部分を以下のように編集します。
“nuxtjs/style-resources”というモジュールを使ってscssファイルを読み込みます。
modules: [
'@nuxtjs/style-resources'
],
styleResources: {
scss: [
'@/assets/scss/variables.scss'
]
},
注意:リセットCSSを使いたい場合
reset.scssとして、使いたい場合は、注意が必要です。
styleResourcesの中に書いても反映されなかったので、僕は、nuxt.config.js内のcss:の中に以下のように記述しました。
解決:
layouts/default.vueに読み込ませる
reset.scssの作成
まずは、assets/scss/reset.scssとなるように準備します。
以下にリセットCSSのサンプルを置いておきます。
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p,
blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
text-decoration: none;
}
nuxt.config.jsの編集
css:の部分を以下のように編集します。
css: [
'@/assets/scss/reset.scss'
],
参考サイト
ハマったこと
今回の設定でハマったことが1つあるので共有します。
nuxt.config.jsのstyleResources:内の部分ですが、scssファイルを使う場合は、
scss:と記述してください。
sass:と書くと読み込まれません。
style-resourcesの公式をみて解決しました。
やっぱり、公式ページを読むのは大切です。。