const fs = require('fs') const path = require('path') const findExisting = (context, files) => { for (const file of files) { if (fs.existsSync(path.join(context, file))) { return file } } } module.exports = (api, options) => { api.chainWebpack(webpackConfig => { const getAssetPath = require('../util/getAssetPath') const { modules = false, extract = true, sourceMap = false, localIdentName = '[name]_[local]_[hash:base64:5]', loaderOptions = {} } = options.css || {} const shadowMode = !!process.env.VUE_CLI_CSS_SHADOW_MODE const isProd = process.env.NODE_ENV === 'production' const shouldExtract = isProd && extract !== false && !shadowMode const extractOptions = Object.assign({ filename: getAssetPath(options, `css/[name].[contenthash:8].css`), chunkFilename: getAssetPath(options, 'css/[name].[contenthash:8].css') }, extract && typeof extract === 'object' ? extract : {}) // check if the project has a valid postcss config // if it doesn't, don't use postcss-loader for direct style imports // because otherwise it would throw error when attempting to load postcss config const hasPostCSSConfig = !!(api.service.pkg.postcss || findExisting(api.resolve('.'), [ '.postcssrc', '.postcssrc.js', 'postcss.config.js', '.postcssrc.yaml', '.postcssrc.json' ])) function createCSSRule (lang, test, loader, options) { const baseRule = webpackConfig.module.rule(lang).test(test) // rules for