Skip to content

Commit 5b3f135

Browse files
committed
fix: refactoring
1 parent e8efeda commit 5b3f135

File tree

9 files changed

+81
-80
lines changed

9 files changed

+81
-80
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuefront-nuxt",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "vuefront-nuxt",
55
"repository": {
66
"type": "git",
@@ -27,6 +27,6 @@
2727
"vue": "^2.6.11",
2828
"vue-graphql-loader": "^0.3.3",
2929
"vue-i18n": "^8.15.3",
30-
"vuefront": "^0.3.0"
30+
"vuefront": "^0.3.1"
3131
}
3232
}

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import setupImages from './setupImages'
55
const path = require('path')
66
const _ = require('lodash')
77
const ampify = require('./plugins/ampify')
8-
var fs = require('fs');
98

109
export default async function vuefrontModule(_moduleOptions) {
1110
const moduleOptions = { ...this.options.vuefront, ..._moduleOptions }

src/plugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ export default async (ctx, inject) => {
127127

128128
<% for (var key in options.themeOptions.extensions) { %>
129129
<% if (options.themeOptions.extensions[key].type === 'full') { %>
130-
extensions.<%= key %> = () => import('<%= options.themeOptions.extensions[key].component %>');
131-
<% } else { %>
130+
extensions.<%= key %> = () => import('<%= options.themeOptions.extensions[key].path %>');<% } else { %>
132131
extensions.<%= key %> = () => import('<%= options.themeOptions.extensions[key].path %>').then(m => m.<%= options.themeOptions.extensions[key].component %>);<% } %><% } %>
133132

134133
const images = {}

src/setupBuild.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default function setupBuild(options, themeOptions) {
22
const VuefrontLoaderPlugin = this.nuxt.resolver.requireModule('vuefront-nuxt/src/webpack/plugin');
3-
this.options.build.transpile.push('vuefront/lib');
3+
this.options.build.transpile.push(/vuefront\/lib/);
44
this.extendBuild((config) => {
55
config.plugins.push(new VuefrontLoaderPlugin({config:themeOptions}))
66
});

src/setupConfig.js

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ const convertPath = (config) => {
2020
result[keys[type]] = {}
2121
for(const key in config[keys[type]]) {
2222
try {
23+
require.resolve(config[keys[type]][key])
2324
result[keys[type]][key] = {
2425
type: 'full',
25-
path: require.resolve(config[keys[type]][key])
26+
path: config[keys[type]][key]
2627
}
2728
} catch(e) {
28-
result[keys[type]][key] = {
29-
type: 'inside',
30-
path: config.root.components,
31-
component: config[keys[type]][key]
29+
try {
30+
require.resolve(config.root.components + '/' +config[keys[type]][key])
31+
result[keys[type]][key] = {
32+
type: 'full',
33+
path: config.root.components + '/' +config[keys[type]][key]
34+
}
35+
} catch(e) {
36+
result[keys[type]][key] = {
37+
type: 'inside',
38+
path: config.root.components,
39+
component: config[keys[type]][key]
40+
}
3241
}
3342
}
3443
}
@@ -44,20 +53,32 @@ const convertPath = (config) => {
4453
continue
4554
}
4655
try {
56+
require.resolve(config.store[key].module)
4757
result.store[key] = {
4858
...config.store[key],
4959
module: {
5060
type: 'full',
51-
path: require.resolve(config.store[key].module)
61+
path: config.store[key].module
5262
}
5363
}
5464
} catch(e) {
55-
result.store[key] = {
56-
...config.store[key],
57-
module: {
58-
type: 'inside',
59-
path: config.root.store,
60-
component: config.store[key].module
65+
try {
66+
require.resolve(config.root.store + '/' + config.store[key].module)
67+
result.store[key] = {
68+
...config.store[key],
69+
module: {
70+
type: 'full',
71+
path: config.root.store + '/' + config.store[key].module
72+
}
73+
}
74+
} catch(e) {
75+
result.store[key] = {
76+
...config.store[key],
77+
module: {
78+
type: 'inside',
79+
path: config.root.store,
80+
component: config.store[key].module
81+
}
6182
}
6283
}
6384
}
@@ -70,21 +91,30 @@ const convertPath = (config) => {
7091
result.locales[key] = []
7192
for (const key2 in config.locales[key]) {
7293
try {
94+
require.resolve(config.locales[key][key2])
7395
result.locales[key][key2] = {
7496
type: 'full',
75-
path: require.resolve(config.locales[key][key2])
97+
path: config.locales[key][key2]
7698
}
7799
} catch(e) {
78-
result.locales[key][key2] = {
79-
type: 'inside',
80-
path: config.root.locales,
81-
component: config.locales[key][key2]
100+
try {
101+
require.resolve(config.root.locales + '/' + config.locales[key][key2])
102+
result.locales[key][key2] = {
103+
type: 'full',
104+
path: config.root.locales + '/' + config.locales[key][key2]
105+
}
106+
} catch(e) {
107+
result.locales[key][key2] = {
108+
type: 'inside',
109+
path: config.root.locales,
110+
component: config.locales[key][key2]
111+
}
82112
}
83113
}
84114
}
85115
}
86116
}
87-
117+
88118
return result
89119
}
90120

src/setupRoutes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ require('isomorphic-fetch')
44
const convertComponent = (component, config) => {
55
if (config.pages[component].type === 'full') {
66
return `import('${config.pages[component].path}').then((m) => {
7-
const component = m || m.default
7+
const component = m.default || m
88
breadcrumbsLoad(component)
99
return component
1010
})`
1111
} else {
1212
return `import('${config.pages[component].path}').then((m) => {
1313
let component = m.${config.pages[component].component}
14-
component = component || component.default
14+
component = component.default || component
1515
breadcrumbsLoad(component)
1616
return component
1717
})`

src/webpack/matcher/tag.js

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,54 @@
11
const _ = require('lodash')
2+
const renderImport = (component, tag) => {
3+
let result = ''
4+
5+
if (component.type === 'full') {
6+
result = `import ${tag} from '${component.path}';`
7+
} else {
8+
result = `import {${component.component} as ${tag}} from '${component.path}';`
9+
}
10+
11+
return result
12+
}
213
const getImport = (name, type, config, tag) => {
314
let comImport = false
415

5-
616
switch (type) {
7-
case 'A':
17+
case 'A':
818
if(!config.atoms[name]) {
919
return
1020
}
11-
if (config.atoms[name].type === 'full') {
12-
comImport = `const ${tag} = () => import('${config.atoms[name].path}');`
13-
} else {
14-
comImport = `const ${tag} = () => import('${config.atoms[name].path}').then(m => m.${config.atoms[name].component});`
15-
}
21+
comImport = renderImport(config.atoms[name], tag)
1622
break;
17-
case 'M':
23+
case 'M':
1824
if(!config.molecules[name]) {
1925
return
2026
}
21-
if (config.molecules[name].type === 'full') {
22-
comImport = `const ${tag} = () => import('${config.molecules[name].path}');`
23-
} else {
24-
comImport = `const ${tag} = () => import('${config.molecules[name].path}').then(m => m.${config.molecules[name].component});`
25-
}
27+
comImport = renderImport(config.molecules[name], tag)
2628
break;
27-
case 'O':
29+
case 'O':
2830
if(!config.organisms[name]) {
2931
return
3032
}
31-
if (config.organisms[name].type === 'full') {
32-
comImport = `const ${tag} = () => import('${config.organisms[name].path}');`
33-
} else {
34-
comImport = `const ${tag} = () => import('${config.organisms[name].path}').then(m => m.${config.organisms[name].component});`
35-
}
33+
comImport = renderImport(config.organisms[name], tag)
3634
break;
37-
case 'T':
35+
case 'T':
3836
if(!config.templates[name]) {
3937
return
4038
}
41-
if (config.templates[name].type === 'full') {
42-
comImport = `const ${tag} = () => import('${config.templates[name].path}');`
43-
} else {
44-
comImport = `const ${tag} = () => import('${config.templates[name].path}').then(m => m.${config.templates[name].component});`
45-
}
39+
comImport = renderImport(config.templates[name], tag)
4640
break;
47-
case 'L':
41+
case 'L':
4842
if(!config.loaders[name]) {
4943
return
5044
}
51-
if (config.loaders[name].type === 'full') {
52-
comImport = `const ${tag} = () => import('${config.loaders[name].path}');`
53-
} else {
54-
comImport = `const ${tag} = () => import('${config.loaders[name].path}').then(m => m.${config.loaders[name].component});`
55-
}
45+
comImport = renderImport(config.loaders[name], tag)
5646
break;
57-
case 'E':
47+
case 'E':
5848
if(!config.extensions[name]) {
5949
return
6050
}
61-
if (config.extensions[name].type === 'full') {
62-
comImport = `const ${tag} = () => import('${config.extensions[name].path}');`
63-
} else {
64-
comImport = `const ${tag} = () => import('${config.extensions[name].path}').then(m => m.${config.extensions[name].component});`
65-
}
51+
comImport = renderImport(config.extensions[name], tag)
6652
break;
6753
}
6854
return comImport
@@ -79,10 +65,5 @@ module.exports = function match (_, config, { kebabTag, camelTag: tag }) {
7965

8066
let comImport = getImport(name, type, config, tag)
8167

82-
if(type === 'O' && name === 'virtual') {
83-
comImport = ''
84-
}
85-
86-
8768
return [tag, comImport]
8869
}

src/webpack/runtime/installComponents.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ module.exports = function installComponents (component, components) {
1414
options.components = options.components || {}
1515

1616
for (var i in components) {
17-
// if(i === 'vf-o-header') {
18-
// console.log(component)
19-
// console.log(components)
20-
// }
21-
// if(i === 'VfOHeader') {
22-
// console.log(component)
23-
// console.log(components)
24-
// }
2517
options.components[i] = options.components[i] || components[i]
2618
}
2719
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,10 +1962,10 @@ vue@^2.6.11:
19621962
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.11.tgz#76594d877d4b12234406e84e35275c6d514125c5"
19631963
integrity sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ==
19641964

1965-
vuefront@^0.3.0:
1966-
version "0.3.0"
1967-
resolved "https://registry.yarnpkg.com/vuefront/-/vuefront-0.3.0.tgz#e92dd8f2b7450531a2d242905c80403509a83252"
1968-
integrity sha512-FNVRMtsHsN4M18klwq7346B/vscP6f4ZZ/yNYysb4nTY1btubDKoCPqWW39co7PGywVWA7nKPrji+xpSV7CLCw==
1965+
vuefront@^0.3.1:
1966+
version "0.3.1"
1967+
resolved "https://registry.yarnpkg.com/vuefront/-/vuefront-0.3.1.tgz#fc6cb4975be5f9fe609483f24d0f87fa87693118"
1968+
integrity sha512-UAk+a75lweZOzBPU4VVru136nt4yGhVdNvkxDv8ht4UHBUnlr5vv+9NS0jMfvCAKEqXBMThgvF91gBh9lOxLvw==
19691969
dependencies:
19701970
"@babel/standalone" "^7.8.4"
19711971
"@fortawesome/fontawesome-free" "^5.12.1"

0 commit comments

Comments
 (0)