首先 運行這行命令css
npm install sass-resources-loader --save-dev;
在項目的build/utils.js中,找到vue
function generateLoaders (loader, loaderOptions){}
並在它的下面插入下面的方法npm
function resolveResource(name) {
return path.resolve(__dirname, '../src/assets/css/' + name);
}
function generateSassResourceLoader() {
var loaders = [
cssLoader,
// 'postcss-loader',
'less-loader',
{
loader: 'sass-resources-loader',
options: {
// it need a absolute path
resources: [resolveResource('basic.less')]
}
}
];
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
注:sass
一、 resolveResource中的‘../src/assets/css’換成本身的less/sass文件的路徑;less
二、generateSassResourceLoader中 resources:[resolveResource('basic.less')]的basic.less換成本身的less/sass文件名post
三、若是用的是sass,則把下面的中的‘less-loader’須要改成 'sass-loader'ui
var loaders = [
cssLoader,
// 'postcss-loader',
'less-loader',
{
loader: 'sass-resources-loader',
options: {
// it need a absolute path
resources: [resolveResource('basic.less')]
}
}
];
而後在build/utils中,找到下面的代碼spa
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
而後進行如下修改.net
less: generateLoaders('less') 替換成 less: generateSassResourceLodaer()
最後從新運行一下項目,okcode
參考文章:https://blog.csdn.net/u014292161/article/details/79193381