1
1
const { resolve } = require ( 'path' )
2
- const { defaultsDeep, cloneDeep } = require ( 'lodash' )
3
-
4
- const defaults = {
5
- css : true ,
6
- rtl : false ,
7
-
8
- f7Icons : true ,
9
- mdIcons : true ,
10
-
11
- routes : { } ,
12
-
13
- mode : 'hash' ,
14
-
15
- view : {
16
- main : true ,
17
- pushState : true ,
18
- pushStateSeparator : '!#' ,
19
- pushStateRoot : null
20
- }
21
- }
2
+ const { defaultsDeep } = require ( 'lodash' )
3
+ const f7BuildConfig = require ( 'framework7/scripts/build-config' )
22
4
23
5
const resolvePath = ( ...args ) => resolve ( __dirname , ...args )
24
- const resolveDep = p => require . resolve ( p )
25
6
26
- module . exports = function nuxt7 ( moduleOptions ) {
27
- const options = defaultsDeep ( { } , moduleOptions , this . options . framework7 , defaults )
28
- const cloneOptions = ( ) => cloneDeep ( options )
7
+ module . exports = function nuxt7 ( _options ) {
8
+ const options = defaultsDeep ( { } , _options , this . options . framework7 , defaults )
29
9
30
10
// Router Mode
31
11
if ( options . mode === 'history' ) {
32
12
options . view . pushStateSeparator = '__window.location.origin ? \'\' : \'#\'__'
33
13
options . view . pushStateRoot = '__window.location.origin__'
34
14
}
35
- delete options . mode
36
15
37
16
// Force mode to SPA
38
17
this . options . mode = 'spa'
@@ -42,35 +21,104 @@ module.exports = function nuxt7 (moduleOptions) {
42
21
// Customize build
43
22
this . extendBuild ( config => extendConfig ( config , options ) )
44
23
45
- // Force add F7 dependencies to common chunk
46
- this . addVendor ( `framework7` )
24
+ // Global theme color
25
+ if ( options . themeColor ) {
26
+ options . build . ios . themeColor = options . themeColor
27
+ options . build . md . themeColor = options . themeColor
28
+
29
+ if ( ! this . options . manifest ) {
30
+ this . options . manifest = { }
31
+ }
32
+ this . options . manifest . theme_color = options . themeColor
33
+ }
34
+
35
+ // Move F7 dependencies to common chunk
47
36
this . addVendor ( `framework7-vue` )
48
37
this . addVendor ( 'dom7' )
49
38
this . addVendor ( 'template7' )
50
39
51
- // Framework7 css files
52
- if ( options . css ) {
53
- this . options . css . push ( resolveDep ( `framework7/dist/css/framework7${ options . rtl ? '.rtl' : '' } .css` ) )
54
- }
55
- delete options . css
40
+ // Add templates
41
+ addTemplates . call ( this , options )
56
42
57
43
// Icons
58
44
if ( options . f7Icons ) {
59
- this . options . css . push ( 'framework7-icons/css/framework7-icons.css' )
45
+ options . f7IconsSrc = 'framework7-icons/css/framework7-icons.css'
60
46
}
61
- delete options . f7Icons
62
47
63
48
if ( options . mdIcons ) {
64
- this . options . css . push ( resolvePath ( 'assets/material-icons/material-icons.css' ) )
49
+ options . mdIconsSrc = resolvePath ( 'assets/material-icons/material-icons.css' )
65
50
}
66
- delete options . mdIcons
51
+
52
+ // Enable IOS specific meta for web app
53
+ if ( ! this . options . meta ) {
54
+ this . options . meta = { }
55
+ }
56
+ this . options . meta . mobileAppIOS = true
57
+
58
+ // Prevent zooming page for a better Native experience
59
+ this . options . meta . viewport = 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, minimal-ui'
60
+
61
+ // Require PWA module
62
+ if ( options . pwa !== false ) {
63
+ return this . requireModule ( '@nuxtjs/pwa' )
64
+ }
65
+
66
+ return Promise . resolve ( )
67
+ }
68
+
69
+ // ----------------------------------------------------------
70
+ // Add templates
71
+ // ----------------------------------------------------------
72
+ function addTemplates ( options ) {
73
+ // --- Framework7 templates ---
74
+
75
+ // Build framework7 from source
76
+ // options.require = require
77
+ // this.addTemplate({
78
+ // src: resolvePath('templates/framework7.js'),
79
+ // fileName: 'framework7.js',
80
+ // options
81
+ // })
82
+
83
+ // Framework7 plugin
84
+ this . addPlugin ( {
85
+ src : resolvePath ( 'templates/f7-plugin.js' ) ,
86
+ fileName : 'f7-plugin.js' ,
87
+ options
88
+ } )
89
+
90
+ // Framework7 routes
91
+ this . addTemplate ( {
92
+ src : resolvePath ( 'templates/f7-router.js' ) ,
93
+ fileName : 'f7-router.js' ,
94
+ options
95
+ } )
96
+
97
+ // Framework7 styles
98
+ if ( options . css ) {
99
+ this . addTemplate ( {
100
+ src : resolvePath ( 'templates/framework7.less' ) ,
101
+ fileName : 'framework7.less' ,
102
+ options
103
+ } )
104
+ }
105
+
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 ---
67
114
68
115
// App.js
69
116
this . addTemplate ( {
70
117
src : resolvePath ( 'templates/App.js' ) ,
71
118
fileName : 'App.js' ,
72
119
options
73
120
} )
121
+
74
122
// ... Support for nuxt <= 1.0.0-rc11
75
123
this . addTemplate ( {
76
124
src : resolvePath ( 'templates/App.vue' ) ,
@@ -84,6 +132,7 @@ module.exports = function nuxt7 (moduleOptions) {
84
132
fileName : 'components/nuxt.js' ,
85
133
options
86
134
} )
135
+
87
136
// ... Support for nuxt <= 1.0.0-rc11
88
137
this . addTemplate ( {
89
138
src : resolvePath ( 'templates/components/nuxt.vue' ) ,
@@ -104,60 +153,47 @@ module.exports = function nuxt7 (moduleOptions) {
104
153
fileName : 'router.js' ,
105
154
options
106
155
} )
107
-
108
- // Framework7 routes
109
- this . addTemplate ( {
110
- src : resolvePath ( 'templates/f7-router.js' ) ,
111
- fileName : 'f7-router.js' ,
112
- options : cloneOptions ( )
113
- } )
114
- delete options . routes
115
-
116
- // Framework7 plugin
117
- this . addPlugin ( {
118
- src : resolvePath ( 'templates/f7.js' ) ,
119
- fileName : 'f7.js' ,
120
- options
121
- } )
122
-
123
- // Framework 7 components
124
- this . addPlugin ( {
125
- src : resolvePath ( 'templates/f7-components.js' ) ,
126
- fileName : 'f7-components.js' ,
127
- options
128
- } )
129
-
130
- // Enable IOS specific meta for web app
131
- if ( ! this . options . meta ) this . options . meta = { }
132
- this . options . meta . mobileAppIOS = true
133
-
134
- // Prevent zooming page for a better Native experience
135
- this . options . meta . viewport = 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, minimal-ui'
136
-
137
- // Require PWA module
138
- return Promise . all ( [
139
- this . requireModule ( '@nuxtjs/pwa' )
140
- ] )
141
156
}
142
157
158
+ // ----------------------------------------------------------
159
+ // Extend webpack config
160
+ // ----------------------------------------------------------
143
161
function extendConfig ( config , options ) {
162
+ // Don't exclude babel for F7 stuff
163
+ const babelLoader = config . module . rules . find ( r => r . loader === 'babel-loader' )
164
+ babelLoader . exclude = / n o d e _ m o d u l e s \/ (? ! ( f r a m e w o r k 7 | f r a m e w o r k 7 - v u e | t e m p l a t e 7 | d o m 7 ) \/ ) .* /
165
+
144
166
// Increase performance check limits to 2M (non-gzipped)
145
167
const MAX_SIZE = 2 * 1024 * 1024
146
168
Object . assign ( config . performance , {
147
169
maxEntrypointSize : MAX_SIZE ,
148
170
maxAssetSize : MAX_SIZE
149
171
} )
150
172
151
- // Don't exclude babel for F7 stuff
152
- const babelLoader = config . module . rules . find ( r => r . loader === 'babel-loader' )
153
- babelLoader . exclude = / n o d e _ m o d u l e s \/ (? ! ( f r a m e w o r k 7 | f r a m e w o r k 7 - v u e | t e m p l a t e 7 | d o m 7 ) \/ ) .* /
154
-
155
173
// Disable warning for babel on framework7 dist files
156
174
babelLoader . options . compact = false
175
+ }
176
+
177
+ // ----------------------------------------------------------
178
+ // Default options
179
+ // ----------------------------------------------------------
180
+ const defaults = {
181
+ css : true ,
182
+ rtl : false ,
183
+
184
+ f7Icons : true ,
185
+ mdIcons : true ,
186
+
187
+ routes : { } ,
157
188
158
- // framework7
159
- config . resolve . alias [ 'framework7' ] = resolveDep ( `framework7/dist/js/framework7.esm.bundle.js` )
189
+ mode : 'hash' ,
190
+
191
+ build : Object . assign ( { } , f7BuildConfig ) ,
160
192
161
- // framework7-vue
162
- config . resolve . alias [ 'framework7-vue' ] = resolveDep ( `framework7-vue/dist/framework7-vue.esm.js` )
193
+ view : {
194
+ main : true ,
195
+ pushState : true ,
196
+ pushStateSeparator : '#' ,
197
+ pushStateRoot : null
198
+ }
163
199
}
0 commit comments