Skip to content

Commit 1f1d4ae

Browse files
GastroGeekrstoenescu
authored andcommitted
Refactored imports and Vue.use() based on prompt responses. Added transform-imports to Babel config. (#6)
1 parent 679bc7d commit 1f1d4ae

File tree

2 files changed

+95
-51
lines changed

2 files changed

+95
-51
lines changed

generator/index.js

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs')
22
const extendPluginOptions = require('../lib/extendPluginOptions')
3-
43
const message = `
54
Documentation can be found at: http://quasar-framework.org
65
@@ -16,6 +15,26 @@ Enjoy! - Quasar Team
1615
`
1716

1817
module.exports = (api, opts, rootOpts) => {
18+
const
19+
defaultComponents = [
20+
'QBtn',
21+
'QLayout',
22+
'QLayoutHeader',
23+
'QLayoutDrawer',
24+
'QPage',
25+
'QPageContainer',
26+
'QToolbar',
27+
'QToolbarTitle',
28+
'QList',
29+
'QListHeader',
30+
'QItemSeparator',
31+
'QItem',
32+
'QItemSide',
33+
'QItemMain',
34+
],
35+
defaultDirectives = [],
36+
defaultPlugins = []
37+
1938
const
2039
tsPath = api.resolve('./src/main.ts'),
2140
jsPath = api.resolve('./src/main.js'),
@@ -27,8 +46,9 @@ module.exports = (api, opts, rootOpts) => {
2746
'quasar-extras': '^2.0.4'
2847
},
2948
devDependencies: {
49+
"babel-plugin-transform-imports": "1.5.0",
3050
'stylus': '^0.54.5',
31-
'stylus-loader': '^3.0.1'
51+
'stylus-loader': '^3.0.2'
3252
}
3353
}
3454

@@ -46,6 +66,15 @@ module.exports = (api, opts, rootOpts) => {
4666
if (opts.quasar.rtlSupport) {
4767
pluginOptions.quasar.rtlSupport = true
4868
}
69+
70+
if (opts.quasar.all) {
71+
pluginOptions.quasar.framework = 'all'
72+
} else {
73+
pluginOptions.quasar.framework = {}
74+
pluginOptions.quasar.framework.components = defaultComponents
75+
pluginOptions.quasar.framework.directives = defaultDirectives
76+
pluginOptions.quasar.framework.plugins = defaultPlugins
77+
}
4978
return pluginOptions
5079
})
5180

@@ -69,24 +98,9 @@ module.exports = (api, opts, rootOpts) => {
6998
let lines = '\n'
7099

71100
const
72-
components = [
73-
'QBtn',
74-
'QLayout',
75-
'QLayoutHeader',
76-
'QLayoutDrawer',
77-
'QPage',
78-
'QPageContainer',
79-
'QToolbar',
80-
'QToolbarTitle',
81-
'QList',
82-
'QListHeader',
83-
'QItemSeparator',
84-
'QItem',
85-
'QItemSide',
86-
'QItemMain',
87-
],
88-
directives = [],
89-
plugins = []
101+
components = defaultComponents,
102+
directives = defaultDirectives,
103+
plugins = defaultPlugins
90104

91105
const
92106
hasLang = opts.quasar.i18n !== 'en-us',
@@ -114,53 +128,49 @@ module.exports = (api, opts, rootOpts) => {
114128
lines += `\nimport 'quasar-extras/${feat}'`
115129
})
116130

117-
lines += `\nimport Quasar, `
131+
// build import
132+
lines += `\nimport `
118133
if (opts.quasar.all) {
119-
lines += `* as All`
134+
lines += `Quasar`
120135
}
121136
else {
122-
lines += `{`
137+
lines += `{\n Quasar, `
123138
components.concat(directives).concat(plugins)
124139
.forEach(part => { lines += `\n ${part},` })
125140
lines += `\n}`
126141
}
127142
lines += ` from 'quasar'`
128143

144+
// build Vue.use()
129145
lines += `\n\nVue.use(Quasar, {`
130-
if (hasIconSet) {
131-
lines += `\n iconSet: iconSet,`
132-
}
133-
if (hasLang) {
134-
lines += `\n i18n: lang,`
135-
}
146+
lines += opts.quasar.all ? ` config: {}` : `\n config: {}`
136147

137-
if (opts.quasar.all) {
138-
lines += `\n components: All,`
139-
lines += `\n directives: All,`
140-
lines += `\n plugins: All`
141-
}
142-
else {
143-
lines += `\n components: {`
144-
components.forEach(comp => {
145-
lines += `\n ${comp},`
146-
})
147-
lines += `\n },`
148+
// if not 'all' we want to include specific defaults
149+
if (!opts.quasar.all) {
150+
lines+= ',\n components: {'
151+
components
152+
.forEach(part => { lines += `\n ${part},` })
153+
lines += `\n }`
148154

149-
lines += `\n directives: {`
150-
directives.forEach(directive => {
151-
lines += `\n ${directive},`
152-
})
153-
lines += `\n },`
155+
lines+= ',\n directives: {'
156+
directives
157+
.forEach(part => { lines += `\n ${part},` })
158+
lines += `\n }`
154159

155-
lines += `\n plugins: {`
156-
plugins.forEach(plugin => {
157-
lines += `\n ${plugin},`
158-
})
160+
lines+= ',\n plugins: {'
161+
plugins
162+
.forEach(part => { lines += `\n ${part},` })
159163
lines += `\n }`
160164
}
161165

162-
lines += `\n})`
166+
if (hasLang) {
167+
lines += `, i18n: lang`
168+
}
169+
if (hasIconSet) {
170+
lines += `, iconSet: iconSet`
171+
}
163172

173+
lines += ` })`
164174

165175
// Now inject additions to main.[js|ts]
166176
{

index.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
module.exports = (api, options) => {
22
const
33
theme = options.pluginOptions.quasar.theme,
4-
rtl = options.pluginOptions.quasar.rtlSupport
4+
rtl = options.pluginOptions.quasar.rtlSupport,
5+
all = options.pluginOptions.quasar.framework === 'all'
56

67
if (rtl) {
78
process.env.QUASAR_RTL = true
89
}
910

1011
api.chainWebpack(chain => {
12+
chain.module.rule('babel')
13+
.test(/\.jsx?$/)
14+
.exclude
15+
.add(filepath => {
16+
// always transpile js(x) in Vue files
17+
if (/\.vue\.jsx?$/.test(filepath)) {
18+
return false
19+
}
20+
21+
if ([/[\\/]node_modules[\\/]quasar-framework[\\/]/].some(dep => filepath.match(dep))) {
22+
return false
23+
}
24+
25+
// don't transpile anything else in node_modules
26+
return /[\\/]node_modules[\\/]/.test(filepath)
27+
})
28+
.end()
29+
.use('babel-loader')
30+
.loader('babel-loader')
31+
.options({
32+
extends: api.resolve('babel.config.js'),
33+
plugins: !all ? [
34+
[
35+
'transform-imports', {
36+
quasar: {
37+
transform: `quasar-framework/dist/babel-transforms/imports.${theme}.js`,
38+
preventFullImport: true
39+
}
40+
}
41+
]
42+
] : []
43+
})
44+
1145
chain
1246
.resolve
1347
.alias

0 commit comments

Comments
 (0)