zhouyl0 2019-07-01
npm i sass-resources-loader --save-dev
return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass'), stylus: generateLoaders('stylus'), styl: generateLoaders('stylus') }
return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass').concat({ loader:'sass-resources-loader', options:{ resources:path.resolve(__dirname,'./../src/assets/scss/base.scss'),// 这里的路径即是我们定义全局变量的地方 } }), stylus: generateLoaders('stylus'), styl: generateLoaders('stylus') }
function lessResourceLoader() { var loaders = [ cssLoader, 'less-loader', { loader: 'sass-resources-loader', options: { resources: [ path.resolve(__dirname, '../src/assets/styles/common.less'),// 这里的路径即是我们定义全局变量的地方 ] } } ]; if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) } } less: generateLoaders('less') 替换成上面自定义的函数 less: lessResourceLoader()