Created
June 2, 2018 04:20
-
-
Save SoarLin/adff9646fb7860716e339877d8ea956a to your computer and use it in GitHub Desktop.
Vue use global SASS resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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