新建 一個公共的stylus公共文件添加公共變量,以下:css
修改下圖圈出的文件:html
具體的修改以下:vue
// generate loader string to be used with extract text plugin function generateLoaders (loader, loaderOptions) { const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] if (loader) { loaders.push({ loader: loader + '-loader', options: Object.assign({}, loaderOptions, { sourceMap: options.sourceMap }) }) } // Extract CSS when that option is specified // (which is the case during production build) if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader', }) } else { return ['vue-style-loader'].concat(loaders) } } var stylusOptions = { import: [ path.join(__dirname, "../src/assets/css/public/var.styl"), // 全局變量文件 文件後綴名爲.styl ] } // https://vue-loader.vuejs.org/en/configurations/extract-css.html return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass'), stylus: generateLoaders('stylus',stylusOptions), styl: generateLoaders('stylus',stylusOptions) }
這裏要特別注意文件後綴名是.styl而不是.stylus哦!sass
而後就能夠在.stylus或者.styl文件(兩種後綴名都是能夠的,統一就好)裏面使用var.styl裏面定義的變量了:less
最後重啓刷新就能夠看到效果啦post