Skip to content

Instantly share code, notes, and snippets.

@SoarLin
Created June 2, 2018 04:20
Show Gist options
  • Save SoarLin/adff9646fb7860716e339877d8ea956a to your computer and use it in GitHub Desktop.
Save SoarLin/adff9646fb7860716e339877d8ea956a to your computer and use it in GitHub Desktop.
Vue use global SASS resource
exports.cssLoaders = function (options) {
options = options || {}
const cssLoader = {...}
const postcssLoader = {...}
function generateLoaders (loader, loaderOptions) {...}
// =========
// SASS 配置
// =========
function resolveResouce(name) {
return path.resolve(__dirname, '../src/assets/sass/' + name);
}
function generateSassResourceLoader() {
let loaders = [
cssLoader,
// 'postcss-loader',
{
loader: 'sass-loader',
options: {
indentedSyntax: true
}
},
{
loader: 'sass-resources-loader',
options: {
// it need a absolute path
// global usage sass file
resources: resolveResouce('resources.sass')
}
}
];
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
} 
return {
css: generateLoaders(),
postcss: generateLoaders(),
less: generateLoaders('less'),
// sass: generateLoaders('sass', { indentedSyntax: true }),
// scss: generateLoaders('sass'),
sass: generateSassResourceLoader(),
scss: generateSassResourceLoader(),
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment