在每一個組件里加載一個設置文件,而無需每次都將其顯式導入,是一個常見的需求。好比爲全部組件全局使用 scss 變量。爲了達成此目的:css
npm install sass-resources-loader --save-dev
而後增長下面的 webpack 規則:html
{
loader: 'sass-resources-loader', options: { resources: path.resolve(__dirname, '../src/style/_variables.scss') } }
舉個例子,若是你使用了 vuejs-templates/webpack,請以下修改 build/utils.js
:vue
scss: generateLoaders('sass').concat( { loader: 'sass-resources-loader', options: { resources: path.resolve(__dirname, '../src/style/_variables.scss') } } ),
在這個文件裏,爲了不在最終編譯後的文件中出現重複的 CSS,建議只包含變量、mixins 等。webpack
來源:vue-loader官方文檔 git
https://vue-loader.vuejs.org/zh-cn/configurations/pre-processors.htmlgithub