Skip to content

Commit ed978c7

Browse files
committed
feat: Support for Vue CLI v5 #52
quasarframework/quasar#12943
1 parent 2468c5e commit ed978c7

8 files changed

+109
-47
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Please submit a PR to https://github.com/quasarframework/quasar-awesome with you
1414

1515
## Getting started
1616

17-
:warning: Make sure you have vue-cli 4.5.1+:
17+
:warning: Make sure you have vue-cli v5:
1818

1919
```
2020
vue --version
2121
```
2222

23-
If you don't have a project created with vue-cli 4.5.1+ yet:
23+
If you don't have a project created with vue-cli v5 yet:
2424

2525
```
2626
# make sure to pick Vue 3 when asked:

Diff for: generator/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ module.exports = (api, opts) => {
4545
if (['sass', 'scss'].includes(opts.quasar.cssPreprocessor)) {
4646
Object.assign(deps.devDependencies, {
4747
'sass': '1.32.12',
48-
'sass-loader': '^10.1.0'
48+
'sass-loader': '^12.0.0'
4949
})
5050
}
5151

5252
if (opts.quasar.rtlSupport) {
53-
deps.devDependencies['postcss-rtl'] = '^1.2.3'
53+
deps.devDependencies['postcss-rtl'] = '^3.5.3'
5454
}
5555

5656
api.extendPackage(deps)

Diff for: index.js

+39-20
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,58 @@ const { version } = getDevlandFile('quasar/package.json')
99
const transformAssetUrls = getDevlandFile('quasar/dist/transforms/loader-asset-urls.json')
1010

1111
function getCssPreprocessor (api) {
12-
return ['sass', 'scss', 'styl'].find(ext => {
12+
return ['sass', 'scss'].find(ext => {
1313
return fs.existsSync(
1414
api.resolve('src/styles/quasar.variables.' + ext)
1515
)
1616
})
1717
}
1818

19+
function applyCssRule (rule, cssPreprocessor) {
20+
rule
21+
.use('quasar-sass-variables-loader')
22+
.loader(path.join(__dirname, `lib/loader.${cssPreprocessor}.js`))
23+
}
24+
25+
function applyCssLoaders (chain, cssPreprocessor) {
26+
const rule = chain.module.rule(cssPreprocessor)
27+
28+
applyCssRule(rule.oneOf('vue-modules'), cssPreprocessor)
29+
applyCssRule(rule.oneOf('vue'), cssPreprocessor)
30+
applyCssRule(rule.oneOf('normal-modules'), cssPreprocessor)
31+
applyCssRule(rule.oneOf('normal'), cssPreprocessor)
32+
}
33+
1934
module.exports = (api, options) => {
2035
if (options.pluginOptions.quasar.rtlSupport) {
2136
process.env.QUASAR_RTL = true
2237
}
2338

2439
const cssPreprocessor = getCssPreprocessor(api)
25-
const srcCssExt = cssPreprocessor === 'scss' ? 'sass' : cssPreprocessor
2640

2741
api.chainWebpack(chain => {
28-
cssPreprocessor && chain.resolve.alias
29-
.set(
30-
'quasar-variables',
31-
api.resolve(`src/styles/quasar.variables.${cssPreprocessor}`)
32-
)
33-
.set(
34-
'quasar-variables-styl',
35-
`quasar/src/css/variables.${srcCssExt}`
36-
)
37-
.set(
38-
'quasar-styl',
39-
`quasar/dist/quasar.${srcCssExt}`
40-
)
41-
.set(
42-
'quasar-addon-styl',
43-
`quasar/src/css/flex-addon.${srcCssExt}`
44-
)
42+
if (cssPreprocessor) {
43+
chain.resolve.alias
44+
.set(
45+
'quasar-variables',
46+
api.resolve(`src/styles/quasar.variables.${cssPreprocessor}`)
47+
)
48+
.set(
49+
'quasar-variables-styl',
50+
`quasar/src/css/variables.sass`
51+
)
52+
.set(
53+
'quasar-styl',
54+
`quasar/dist/quasar.sass`
55+
)
56+
.set(
57+
'quasar-addon-styl',
58+
`quasar/src/css/flex-addon.sass`
59+
)
60+
61+
applyCssLoaders(chain, 'sass')
62+
applyCssLoaders(chain, 'scss')
63+
}
4564

4665
chain.plugin('define-quasar')
4766
.use(webpack.DefinePlugin, [{
@@ -69,7 +88,7 @@ module.exports = (api, options) => {
6988
.use('vue-auto-import-quasar')
7089
.loader(path.join(__dirname, 'lib/loader.vue.auto-import-quasar.js'))
7190
.options({ strategy })
72-
.before('cache-loader')
91+
.before('vue-loader')
7392

7493
chain.module.rule('js-transform-quasar-imports')
7594
.test(/\.(t|j)sx?$/)

Diff for: lib/loader.js.transform-quasar-imports.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const getDevlandFile = require('./get-devland-file.js')
1+
const getDevlandFile = require('./get-devland-file')
22
const importTransformation = getDevlandFile('quasar/dist/transforms/import-transformation.js')
33

44
const regex = /import\s*\{([\w,\s]+)\}\s*from\s*['"]{1}quasar['"]{1}/g

Diff for: lib/loader.sass.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
const prefix = `@import 'quasar-variables', 'quasar/src/css/variables.sass'\n`
3+
4+
module.exports = function (content) {
5+
if (content.indexOf('$') !== -1) {
6+
let useIndex = Math.max(
7+
content.lastIndexOf('@use '),
8+
content.lastIndexOf('@forward ')
9+
)
10+
11+
if (useIndex === -1) {
12+
return prefix + content
13+
}
14+
15+
const newLineIndex = content.indexOf('\n', useIndex) + 1
16+
return content.substr(0, newLineIndex) + prefix + content.substr(newLineIndex)
17+
}
18+
19+
return content
20+
}

Diff for: lib/loader.scss.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
const prefix = `@import 'quasar-variables', 'quasar/src/css/variables.sass';\n`
3+
4+
module.exports = function (content) {
5+
if (content.indexOf('$') !== -1) {
6+
let useIndex = Math.max(
7+
content.lastIndexOf('@use '),
8+
content.lastIndexOf('@forward ')
9+
)
10+
11+
if (useIndex === -1) {
12+
return prefix + content
13+
}
14+
15+
const newLineIndex = content.indexOf('\n', useIndex) + 1
16+
return content.substr(0, newLineIndex) + prefix + content.substr(newLineIndex)
17+
}
18+
19+
return content
20+
}

Diff for: lib/loader.vue.auto-import-quasar.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
const { getOptions } = require('loader-utils')
2+
13
const stringifyRequest = require('loader-utils/lib/stringifyRequest')
2-
const getDevlandFile = require('./get-devland-file.js')
4+
const getDevlandFile = require('./get-devland-file')
5+
36
const autoImportData = getDevlandFile('quasar/dist/transforms/auto-import.json')
47
const importTransformation = getDevlandFile('quasar/dist/transforms/import-transformation.js')
5-
6-
const runtimePath = require.resolve('./runtime.auto-import.js')
8+
const autoImportRuntimePath = require.resolve('./runtime.auto-import.js')
79

810
const compRegex = {
911
'kebab': new RegExp(autoImportData.regex.kebabComponents || autoImportData.regex.components, 'g'),
@@ -19,11 +21,8 @@ function transform (itemArray) {
1921
.join(`\n`)
2022
}
2123

22-
function extract (content, ctx) {
23-
// Use webpack v5 getOptions or fallback to ctx.query for webpack v4
24-
const { strategy } = ctx.getOptions ? ctx.getOptions() : ctx.query
25-
26-
let comp = content.match(compRegex[strategy])
24+
function extract (content, ctx, autoImportCase) {
25+
let comp = content.match(compRegex[autoImportCase])
2726
let dir = content.match(dirRegex)
2827

2928
if (comp === null && dir === null) {
@@ -38,11 +37,11 @@ function extract (content, ctx) {
3837
comp = Array.from(new Set(comp))
3938

4039
// map comp names only if not pascal-case already
41-
if (strategy !== 'pascal') {
40+
if (autoImportCase !== 'pascal') {
4241
comp = comp.map(name => autoImportData.importName[name])
4342
}
4443

45-
if (strategy === 'combined') {
44+
if (autoImportCase === 'combined') {
4645
// could have been transformed QIcon and q-icon too,
4746
// so avoid duplicates
4847
comp = Array.from(new Set(comp))
@@ -64,7 +63,7 @@ function extract (content, ctx) {
6463
// messes up consistency of hashes between builds
6564
return `
6665
${importStatements}
67-
import qInstall from ${stringifyRequest(ctx, runtimePath)};
66+
import qInstall from ${stringifyRequest(ctx, autoImportRuntimePath)};
6867
${installStatements}
6968
`
7069
}
@@ -73,17 +72,21 @@ module.exports = function (content, map) {
7372
let newContent = content
7473

7574
if (!this.resourceQuery) {
76-
const file = this.fs.readFileSync(this.resource, 'utf-8').toString()
77-
const code = extract(file, this)
75+
const opts = getOptions(this)
76+
77+
if (opts.isServerBuild !== true) {
78+
const file = this.fs.readFileSync(this.resource, 'utf-8').toString()
79+
const code = extract(file, this, opts.strategy)
7880

79-
if (code !== void 0) {
80-
const index = this.mode === 'development'
81-
? content.indexOf('/* hot reload */')
82-
: -1
81+
if (code !== void 0) {
82+
const index = this.mode === 'development'
83+
? content.indexOf('/* hot reload */')
84+
: -1
8385

84-
newContent = index === -1
85-
? content + code
86-
: content.slice(0, index) + code + content.slice(index)
86+
newContent = index === -1
87+
? content + code
88+
: content.slice(0, index) + code + content.slice(index)
89+
}
8790
}
8891
}
8992

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-cli-plugin-quasar",
3-
"version": "4.0.4",
4-
"description": "Quasar Framework v2 plugin for Vue CLI v4+",
3+
"version": "5.0.0",
4+
"description": "Quasar Framework v2 plugin for Vue CLI v5",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)