打开命令行
npm install node-sass --save-dev //安装node-sass npm install sass-loader --save-dev //安装sass-loader npm install style-loader --save-dev //安装style-loader 有些人安装的是 vue-style-loader 其实是一样的!
连续安装三个麻烦的话,来个快捷的方式
npm install sass-loader node-sass vue-style-loader --D
//卸载sass
npm uninstall --save-dev sass-loader
npm uninstall --save-dev node-sass
打开build文件夹下面的webpack.base.config.js,如下修改
module: { rules: [ ...(config.dev.useEslint ? [createLintingRule()] : []), { test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('media/[name].[hash:7].[ext]') } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } }, { //上面的不修改,这是sass的配置 test: /\.scss$/, loaders: ['style', 'css', 'sass'] } ] },
在 .vue 的编程页面上,style上加 lang='scss'
在引入sass文件是sass文件后缀为 .scss