diff --git a/lib/build/app-paths.js b/lib/build/app-paths.js index 91997d9..986fe49 100644 --- a/lib/build/app-paths.js +++ b/lib/build/app-paths.js @@ -42,6 +42,8 @@ module.exports = { entryTemplateFile: resolve(cliDir, 'templates/app/entry.js'), entryFile: resolve(appDir, '.quasar/entry.js'), + quasarTemplateFile: resolve(cliDir, 'templates/app/quasar.js'), + quasarFile: resolve(appDir, '.quasar/quasar.js'), resolve: { cli: dir => join(cliDir, dir), diff --git a/lib/generator.js b/lib/generator.js index 88b202d..04be31e 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -11,8 +11,8 @@ const class Generator { constructor () { - const content = fs.readFileSync(appPaths.entryTemplateFile, 'utf-8') - this.template = compileTemplate(content) + this.entryTemplate = compileTemplate(fs.readFileSync(appPaths.entryTemplateFile, 'utf-8')) + this.quasarTemplate = compileTemplate(fs.readFileSync(appPaths.quasarTemplateFile, 'utf-8')) } build (quasarConfig) { @@ -20,13 +20,15 @@ class Generator { const data = quasarConfig.getBuildConfig() fse.mkdirpSync(dirname(appPaths.entryFile)) - fs.writeFileSync(appPaths.entryFile, this.template(data), 'utf-8') + fs.writeFileSync(appPaths.entryFile, this.entryTemplate(data), 'utf-8') + fs.writeFileSync(appPaths.quasarFile, this.quasarTemplate(data), 'utf-8') const now = Date.now() / 1000, then = now - 10 fs.utimes(appPaths.entryFile, then, then, function (err) { if (err) throw err }) + fs.utimes(appPaths.quasarFile, then, then, function (err) { if (err) throw err }) if (!fse.existsSync(destAppStylFile)) { const diff --git a/templates/app/entry.js b/templates/app/entry.js index 530825a..81447d7 100644 --- a/templates/app/entry.js +++ b/templates/app/entry.js @@ -7,38 +7,10 @@ * One plugin per concern. Then reference the file(s) in quasar.conf.js > plugins: * plugins: ['file', ...] // do not add ".js" extension to it. **/ -<% -function hash (str) { - const name = str.replace(/\W+/g, '') - return name.charAt(0).toUpperCase() + name.slice(1) -} - -let QImports, QOptions = [] -if (framework === 'all') { - QImports = ', * as All' - QOptions = ', {components: All, directives: All, plugins: All}' -} -else if (framework !== false) { - let options = [] - ;['components', 'directives', 'plugins'].forEach(type => { - if (framework[type]) { - let items = framework[type].filter(item => item) - if (items.length > 0) { - QOptions.push(type + ': {' + items.join(',') + '}') - options = options.concat(items) - } - } - }) - if (options.length) { - QImports = ', {' + options.join(',') + '}' - QOptions = ', {' + QOptions.join(',') + '}' - } -} -%> +import Vue from 'vue' +import './quasar' -<% if (supportIE) { %> -import 'quasar-framework/dist/quasar.ie.polyfills' -<% } %> +Vue.config.productionTip = false <% extras && extras.filter(asset => asset).forEach(asset => { @@ -69,23 +41,8 @@ import 'quasar-app-styl' import 'src/css/<%= asset %>' <% }) %> -import Vue from 'vue' -import Quasar<%= QImports || '' %> from 'quasar' - -Vue.config.productionTip = false import App from 'src/App' -Vue.use(Quasar<%= QImports ? QOptions : '' %>) - -<% if (framework && framework.i18n) { %> -import lang from 'quasar-framework/i18n/<%= framework.i18n %>' -Quasar.i18n.set(lang) -<% } %> -<% if (framework && framework.iconSet) { %> -import iconSet from 'quasar-framework/icons/<%= framework.iconSet %>' -Quasar.icons.set(iconSet) -<% } %> - import router from 'src/router' <% if (store) { %> import store from 'src/store' @@ -98,7 +55,13 @@ const app = { ...App } -<% if (plugins) { %> +<% + if (plugins) { + function hash (str) { + const name = str.replace(/\W+/g, '') + return name.charAt(0).toUpperCase() + name.slice(1) + } +%> const plugins = [] <% plugins.filter(asset => asset).forEach(asset => { diff --git a/templates/app/quasar.js b/templates/app/quasar.js new file mode 100644 index 0000000..073bb7a --- /dev/null +++ b/templates/app/quasar.js @@ -0,0 +1,49 @@ +/** + * THIS FILE IS GENERATED AUTOMATICALLY. + * DO NOT EDIT. + * + * You are probably looking on adding initialization code. + * Use "quasar new plugin " and add it there. + * One plugin per concern. Then reference the file(s) in quasar.conf.js > plugins: + * plugins: ['file', ...] // do not add ".js" extension to it. + **/ +<% +let QImports, QOptions = [] +if (framework === 'all') { + QImports = ', * as All' + QOptions = ', {components: All, directives: All, plugins: All}' +} +else if (framework !== false) { + let options = [] + ;['components', 'directives', 'plugins'].forEach(type => { + if (framework[type]) { + let items = framework[type].filter(item => item) + if (items.length > 0) { + QOptions.push(type + ': {' + items.join(',') + '}') + options = options.concat(items) + } + } + }) + if (options.length) { + QImports = ', {' + options.join(',') + '}' + QOptions = ', {' + QOptions.join(',') + '}' + } +} + +if (supportIE) { %> +import 'quasar-framework/dist/quasar.ie.polyfills' +<% } %> + +import Vue from 'vue' +import Quasar<%= QImports || '' %> from 'quasar' + +Vue.use(Quasar<%= QImports ? QOptions : '' %>) + +<% if (framework && framework.i18n) { %> +import lang from 'quasar-framework/i18n/<%= framework.i18n %>' +Quasar.i18n.set(lang) +<% } %> +<% if (framework && framework.iconSet) { %> +import iconSet from 'quasar-framework/icons/<%= framework.iconSet %>' +Quasar.icons.set(iconSet) +<% } %>