一、npm install sass-resources-loader --save-dev;javascript
二、build/utils.js中,修改css
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) } }
其中resolveResource中的‘../src/assets/css’換成本身的less/sass文件的路徑,generateSassResourceLoader中vue
resources:[resolveResource('basic.less')]的basic.less換成本身的less/sass文件名;(注意:若是是sass,則java
var loaders = [ cssLoader, // 'postcss-loader', 'less-loader', { loader: 'sass-resources-loader', options: { // it need a absolute path resources: [resolveResource('basic.less')] } } ];
中的‘less-loader’須要改成 'sass-loader');npm
三、build/utils.js中,把sass
less: generateLoaders('less') 替換成 less: generateSassResourceLoaer()
參考: https://blog.csdn.net/u014292161/article/details/79193381less