1,使用save會在package.json中自動添加。css
npm install node-sass --save-dev npm install sass-loader --save-dev
注:html
一般使用npm安裝會出現如下報錯,安裝失敗。(網路問題)vue
能夠經過淘寶的npm鏡像安裝node-sass,解決以上問題。node
$ npm install -g cnpm --registry=https://registry.npm.taobao.org (安裝淘寶鏡像)webpack
$ cnpm install node-sass --save (使用淘寶鏡像安裝node-sass)web
注:安裝淘寶鏡像後,仍沒法安裝node-sass的狀況,執行下列命令npm
$ npm install --save node-sass --registry=https://registry.npm.taobao.org --disturl=https://npm.taobao.org/dist --sass-binary-site=http://npm.taobao.org/mirrors/node-sass 說明: --registry=https://registry.npm.taobao.org 淘寶npm包鏡像 --disturl=https://npm.taobao.org/dist 淘寶node源碼鏡像,一些二進制包編譯時用 --sass-binary-site=http://npm.taobao.org/mirrors/node-sass 這個纔是node-sass鏡像
2.進入webpack.base.config.js 配置scss module -- loaders (vue1.0)json
$ npm install --save-dev sass-loader style-loader css-loadersass
{ test: /\.vue$/, loader: 'vue-loader', options: { loaders: { 'scss': 'style-loader!css-loader!sass-loader' } } }
打開webpack.base.config.js在loaders裏面加上 module -- rules (vue2.0)babel
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
}
3.若是須要在vue文件style標籤使用scss的話,須要聲明一下:
vue1.0
<style rel="stylesheet/scss" lang="scss"></style>
vue2.0
<style lang="scss" scoped="" type="text/css"></style>
.