Skip to content

Commit

Permalink
feat(app-webpack): support more babel & postcss config filenames #15756
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Apr 29, 2023
1 parent 07fb8ec commit df25068
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 25 deletions.
33 changes: 33 additions & 0 deletions app-webpack/lib/app-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ function getAppInfo () {
fatal(`Error. This command must be executed inside a Quasar project folder.`)
}

const postcssConfigFilenameList = [
'.postcssrc.js',
'postcss.config.js',
'postcss.config.cjs'
]

function getPostcssConfigFile (appDir) {
for (const name of postcssConfigFilenameList) {
const filename = join(appDir, name)
if (existsSync(filename)) {
return filename
}
}
}

const babelConfigFilenameList = [
'babel.config.js',
'babel.config.cjs',
'.babelrc.js'
]

function getBabelConfigFile (appDir) {
for (const name of babelConfigFilenameList) {
const filename = join(appDir, name)
if (existsSync(filename)) {
return filename
}
}
}

const { appDir, quasarConfigFilename } = getAppInfo()

const cliDir = resolve(__dirname, '..')
Expand All @@ -47,7 +77,10 @@ module.exports = {
capacitorDir,
electronDir,
bexDir,

quasarConfigFilename,
postcssConfigFilename: getPostcssConfigFile(appDir),
babelConfigFilename: getBabelConfigFile(appDir),

resolve: {
cli: dir => join(cliDir, dir),
Expand Down
29 changes: 12 additions & 17 deletions app-webpack/lib/helpers/has-eslint.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
const fs = require('fs')

const { existsSync } = require('fs')

const appPaths = require('../app-paths')
const appPkg = require(appPaths.resolve.app('package.json'))

function hasEslint() {
// See: https://eslint.org/docs/user-guide/configuring/configuration-files
const configPaths = [
'.eslintrc.js',
'.eslintrc.cjs',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.json',
]

return (
configPaths.some(path => fs.existsSync(appPaths.resolve.app(path))) ||
appPkg.eslintConfig !== undefined
)
}
const eslintConfigFile = [
'.eslintrc.cjs',
'.eslintrc.js',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.json',
].find(path => existsSync(appPaths.resolve.app(path)))

module.exports = hasEslint()
module.exports.eslintConfigFile = eslintConfigFile
module.exports.hasEslint = appPkg.eslintConfig || eslintConfigFile
4 changes: 2 additions & 2 deletions app-webpack/lib/mode/mode-pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const appPaths = require('../app-paths')
const { log, warn } = require('../helpers/logger')
const nodePackager = require('../helpers/node-packager')
const hasTypescript = require('../helpers/has-typescript')
const hasEslint = require('../helpers/has-eslint')
const { hasEslint } = require('../helpers/has-eslint')

const pwaDeps = {
'workbox-webpack-plugin': '^6.0.0'
Expand Down Expand Up @@ -34,7 +34,7 @@ class Mode {
appPaths.resolve.cli(`templates/pwa/${format}`),
appPaths.pwaDir,
// Copy .eslintrc.js only if the app has ESLint
{ filter: src => hasEslint || !src.endsWith('/.eslintrc.js') }
hasEslint === true && format === 'ts' ? { filter: src => !src.endsWith('/.eslintrc.js') } : void 0
)

fse.copySync(
Expand Down
2 changes: 1 addition & 1 deletion app-webpack/lib/webpack/create-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module.exports = function (cfg, configName) {
.loader('babel-loader')
.options({
compact: false,
extends: appPaths.resolve.app('babel.config.js')
extends: appPaths.babelConfigFilename
})
}

Expand Down
2 changes: 1 addition & 1 deletion app-webpack/lib/webpack/inject.node-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (cfg, chain) {
.use('babel-loader')
.loader('babel-loader')
.options({
extends: appPaths.resolve.app('babel.config.js')
extends: appPaths.babelConfigFilename
})
}
}
5 changes: 2 additions & 3 deletions app-webpack/lib/webpack/inject.style-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path')

const appPaths = require('../app-paths')
const cssVariables = require('../helpers/css-variables')
const postCssConfigFile = appPaths.resolve.app('.postcssrc.js')
const quasarCssPaths = [
path.join('node_modules', 'quasar', 'dist'),
path.join('node_modules', 'quasar', 'src'),
Expand Down Expand Up @@ -113,8 +112,8 @@ function injectRule (chain, pref, lang, test, loader, loaderOptions) {

// need a fresh copy, otherwise plugins
// will keep on adding making N duplicates for each one
delete require.cache[postCssConfigFile]
const postCssConfig = require(postCssConfigFile)
delete require.cache[appPaths.postcssConfigFilename]
const postCssConfig = require(appPaths.postcssConfigFilename)
let postCssOpts = { sourceMap: pref.sourceMap, ...postCssConfig }

if (pref.rtl) {
Expand Down
2 changes: 1 addition & 1 deletion app-webpack/lib/webpack/pwa/create-custom-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = function (cfg, configName) {
.loader('babel-loader')
.options({
compact: false,
extends: appPaths.resolve.app('babel.config.js')
extends: appPaths.babelConfigFilename
})
}

Expand Down

0 comments on commit df25068

Please sign in to comment.