1
1
const { resolve, relative } = require ( 'path' )
2
- const { defaultsDeep, omit } = require ( 'lodash' )
2
+ const { defaultsDeep, omit, startCase } = require ( 'lodash' )
3
3
const f7BuildConfig = require ( './f7-config' )
4
4
5
5
const resolvePath = ( ...args ) => resolve ( __dirname , ...args )
6
6
7
7
module . exports = function nuxt7 ( _options ) {
8
8
const options = defaultsDeep ( { } , _options , this . options . framework7 , defaults )
9
9
10
+ // CamelCase component names
11
+ options . build . _components = normalizeComponents ( options . build . components )
12
+
10
13
// Router Mode
11
14
if ( options . mode === 'history' ) {
12
15
options . view . pushStateSeparator = "__window.location.origin ? '' : '#'__"
@@ -21,9 +24,6 @@ module.exports = function nuxt7 (_options) {
21
24
// Disable postcss for less transformations
22
25
this . options . build . postcss = false
23
26
24
- // Customize build
25
- this . extendBuild ( config => extendConfig ( config , options ) )
26
-
27
27
// Global theme color
28
28
if ( options . themeColor ) {
29
29
options . build . ios . themeColor = options . themeColor
@@ -40,6 +40,9 @@ module.exports = function nuxt7 (_options) {
40
40
this . addVendor ( 'dom7' )
41
41
this . addVendor ( 'template7' )
42
42
43
+ // Remove custom keys for framework7 plugin
44
+ options . plugin = omit ( options , extraKeys )
45
+
43
46
// Add templates
44
47
addTemplates . call ( this , options )
45
48
@@ -78,86 +81,64 @@ module.exports = function nuxt7 (_options) {
78
81
// Add templates
79
82
// ----------------------------------------------------------
80
83
function addTemplates ( options ) {
81
- // --- Framework7 templates ---
82
-
83
84
// Framework7 plugin
84
85
this . addPlugin ( {
85
- src : resolvePath ( 'templates/f7-plugin.js' ) ,
86
- fileName : 'f7-plugin.js' ,
87
- options : omit ( options , extraKeys )
88
- } )
89
-
90
- // Framework7 routes
91
- this . addTemplate ( {
92
- src : resolvePath ( 'templates/f7-router.js' ) ,
93
- fileName : 'f7-router.js' ,
86
+ src : resolvePath ( 'templates/framework7/f7.plugin.js' ) ,
87
+ fileName : 'framework7/f7.plugin.js' ,
94
88
options
95
89
} )
96
90
97
- // Framework7 styles
98
- if ( options . css ) {
91
+ // Copy all templates
92
+ for ( const template of templates ) {
99
93
this . addTemplate ( {
100
- src : resolvePath ( 'templates/framework7.less' ) ,
101
- fileName : 'framework7.less' ,
94
+ src : resolvePath ( 'templates/' + template ) ,
95
+ fileName : template ,
102
96
options
103
97
} )
104
98
}
99
+ }
105
100
106
- // Framework 7 components
107
- this . addTemplate ( {
108
- src : resolvePath ( 'templates/f7-components.js' ) ,
109
- fileName : 'f7-components.js' ,
110
- options
111
- } )
112
-
113
- // --- Nuxt internals ---
114
-
115
- // App.js
116
- this . addTemplate ( {
117
- src : resolvePath ( 'templates/App.js' ) ,
118
- fileName : 'App.js' ,
119
- options
120
- } )
121
-
122
- // Nuxt component
123
- this . addTemplate ( {
124
- src : resolvePath ( 'templates/components/nuxt.js' ) ,
125
- fileName : 'components/nuxt.js' ,
126
- options
127
- } )
128
-
129
- // Default layout
130
- this . addTemplate ( {
131
- src : resolvePath ( 'templates/layouts/default.vue' ) ,
132
- fileName : 'layouts/default.vue' ,
133
- options
134
- } )
135
-
136
- // Vue router
137
- this . addTemplate ( {
138
- src : resolvePath ( 'templates/router.js' ) ,
139
- fileName : 'router.js' ,
140
- options
141
- } )
101
+ function tryResolve ( path ) {
102
+ try {
103
+ return require . resolve ( path )
104
+ } catch ( err ) {
105
+ return null
106
+ }
142
107
}
143
108
144
- // ----------------------------------------------------------
145
- // Extend webpack config
146
- // ----------------------------------------------------------
147
- function extendConfig ( config , options ) {
148
- // Increase performance check limits to 2M (non-gzipped)
149
- const MAX_SIZE = 2 * 1024 * 1024
150
- Object . assign ( config . performance , {
151
- maxEntrypointSize : MAX_SIZE ,
152
- maxAssetSize : MAX_SIZE
153
- } )
109
+ function normalizeComponents ( components ) {
110
+ return components . map ( ( name ) => ( {
111
+ name,
112
+ camelName : startCase ( name ) . replace ( / / g, '' ) ,
113
+ js : tryResolve ( `framework7/dist/components/${ name } /${ name } .js` ) ,
114
+ less : tryResolve ( `framework7/dist/components/${ name } /${ name } .less` )
115
+ } ) )
154
116
}
155
117
156
- // ----------------------------------------------------------
157
- // Default options
158
- // ----------------------------------------------------------
118
+ const templates = [
119
+ // Framework 7
120
+ 'framework7/f7.router.js' ,
121
+ 'framework7/f7.styles.less' ,
122
+ 'framework7/f7.components.js' ,
123
+ // Nuxt
124
+ 'App.js' ,
125
+ 'components/nuxt.js' ,
126
+ 'layouts/default.vue' ,
127
+ 'router.js'
128
+ ]
129
+
159
130
const extraKeys = [
160
- 'build' , 'mode' , 'themeColor' , 'css' , 'f7Icons' , 'mdIcons' , 'f7IconsSrc' , 'mdIconsSrc' , 'pwa' , 'routes'
131
+ 'build' ,
132
+ 'mode' ,
133
+ 'themeColor' ,
134
+ 'css' ,
135
+ 'f7Icons' ,
136
+ 'mdIcons' ,
137
+ 'f7IconsSrc' ,
138
+ 'mdIconsSrc' ,
139
+ 'pwa' ,
140
+ 'routes' ,
141
+ 'plugin'
161
142
]
162
143
163
144
const defaults = {
0 commit comments