Skip to content

Commit df25068

Browse files
committed
feat(app-webpack): support more babel & postcss config filenames #15756
1 parent 07fb8ec commit df25068

File tree

7 files changed

+52
-25
lines changed

7 files changed

+52
-25
lines changed

app-webpack/lib/app-paths.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@ function getAppInfo () {
2626
fatal(`Error. This command must be executed inside a Quasar project folder.`)
2727
}
2828

29+
const postcssConfigFilenameList = [
30+
'.postcssrc.js',
31+
'postcss.config.js',
32+
'postcss.config.cjs'
33+
]
34+
35+
function getPostcssConfigFile (appDir) {
36+
for (const name of postcssConfigFilenameList) {
37+
const filename = join(appDir, name)
38+
if (existsSync(filename)) {
39+
return filename
40+
}
41+
}
42+
}
43+
44+
const babelConfigFilenameList = [
45+
'babel.config.js',
46+
'babel.config.cjs',
47+
'.babelrc.js'
48+
]
49+
50+
function getBabelConfigFile (appDir) {
51+
for (const name of babelConfigFilenameList) {
52+
const filename = join(appDir, name)
53+
if (existsSync(filename)) {
54+
return filename
55+
}
56+
}
57+
}
58+
2959
const { appDir, quasarConfigFilename } = getAppInfo()
3060

3161
const cliDir = resolve(__dirname, '..')
@@ -47,7 +77,10 @@ module.exports = {
4777
capacitorDir,
4878
electronDir,
4979
bexDir,
80+
5081
quasarConfigFilename,
82+
postcssConfigFilename: getPostcssConfigFile(appDir),
83+
babelConfigFilename: getBabelConfigFile(appDir),
5184

5285
resolve: {
5386
cli: dir => join(cliDir, dir),
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
const fs = require('fs')
1+
2+
const { existsSync } = require('fs')
3+
24
const appPaths = require('../app-paths')
35
const appPkg = require(appPaths.resolve.app('package.json'))
46

5-
function hasEslint() {
6-
// See: https://eslint.org/docs/user-guide/configuring/configuration-files
7-
const configPaths = [
8-
'.eslintrc.js',
9-
'.eslintrc.cjs',
10-
'.eslintrc.yaml',
11-
'.eslintrc.yml',
12-
'.eslintrc.json',
13-
]
14-
15-
return (
16-
configPaths.some(path => fs.existsSync(appPaths.resolve.app(path))) ||
17-
appPkg.eslintConfig !== undefined
18-
)
19-
}
7+
const eslintConfigFile = [
8+
'.eslintrc.cjs',
9+
'.eslintrc.js',
10+
'.eslintrc.yaml',
11+
'.eslintrc.yml',
12+
'.eslintrc.json',
13+
].find(path => existsSync(appPaths.resolve.app(path)))
2014

21-
module.exports = hasEslint()
15+
module.exports.eslintConfigFile = eslintConfigFile
16+
module.exports.hasEslint = appPkg.eslintConfig || eslintConfigFile

app-webpack/lib/mode/mode-pwa.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const appPaths = require('../app-paths')
55
const { log, warn } = require('../helpers/logger')
66
const nodePackager = require('../helpers/node-packager')
77
const hasTypescript = require('../helpers/has-typescript')
8-
const hasEslint = require('../helpers/has-eslint')
8+
const { hasEslint } = require('../helpers/has-eslint')
99

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

4040
fse.copySync(

app-webpack/lib/webpack/create-chain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ module.exports = function (cfg, configName) {
175175
.loader('babel-loader')
176176
.options({
177177
compact: false,
178-
extends: appPaths.resolve.app('babel.config.js')
178+
extends: appPaths.babelConfigFilename
179179
})
180180
}
181181

app-webpack/lib/webpack/inject.node-babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function (cfg, chain) {
1010
.use('babel-loader')
1111
.loader('babel-loader')
1212
.options({
13-
extends: appPaths.resolve.app('babel.config.js')
13+
extends: appPaths.babelConfigFilename
1414
})
1515
}
1616
}

app-webpack/lib/webpack/inject.style-rules.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const path = require('path')
44

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

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

120119
if (pref.rtl) {

app-webpack/lib/webpack/pwa/create-custom-sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = function (cfg, configName) {
9191
.loader('babel-loader')
9292
.options({
9393
compact: false,
94-
extends: appPaths.resolve.app('babel.config.js')
94+
extends: appPaths.babelConfigFilename
9595
})
9696
}
9797

0 commit comments

Comments
 (0)