Skip to content

Commit 26ba92e

Browse files
committed
adjusted templates to have different css for NVW
added copy-webpack-plugin to webpack config for web/nvw projects adjusted output path for url-loader fallback to file-loader
1 parent ea813cb commit 26ba92e

File tree

4 files changed

+94
-13
lines changed

4 files changed

+94
-13
lines changed

Diff for: generator/templates/simple/without-nvw/src/components/HelloWorld.vue

+17-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
</template>
1616
<%_ } else { _%>
1717
<%_ } _%>
18-
19-
2018
<%_ if (!usingTS) { _%>
2119
<%_ if (!usingNVW) { _%>
2220
<script>
@@ -78,7 +76,6 @@
7876
</script>
7977
<%_ } _%>
8078
<%_ } _%>
81-
8279
<!-- Add "scoped" attribute to limit CSS to this component only -->
8380
<%_ if (rootOptions.cssPreprocessor !== 'stylus') { _%>
8481
<style scoped<%-
@@ -98,13 +95,22 @@
9895
text-align: center;
9996
}
10097

98+
<%_ if (!usingNVW) { _%>
10199
img {
102100
height: 20%;
103101
width: 20%;
104102
display: block;
105103
margin: auto;
106104
margin-top: 4em;
107105
}
106+
<%_ } else { _%>
107+
<%# Is using NVW %>
108+
img {
109+
display: block;
110+
margin: auto;
111+
margin-top: 4em;
112+
}
113+
<%_ } _%>
108114
</style>
109115
<%_ } else { _%>
110116
<style scoped lang="stylus">
@@ -114,12 +120,18 @@
114120
margin auto
115121
margin-top 4em
116122
text-align center
117-
123+
<%_ if (!usingNVW) { _%>
118124
.img
119125
height 20%
120126
width 20%
121127
display block
122128
margin auto
123129
margin-top 4em
124-
</style>
130+
<%_ } else { _%>
131+
<%# Is using NVW %>
132+
.img
133+
display block
134+
margin auto
135+
margin-top 4em
136+
<%_ } _%></style>
125137
<%_ } _%>

Diff for: generator/templates/simple/without-nvw/src/views/About.vue

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
</template>
2828
<%_ } _%>
2929
<%_ } _%>
30-
3130
<%_ if (!rootOptions.router) { _%>
3231
<%_ if (!usingTS) { _%>
3332
<%_ if (!usingNVW) { _%>

Diff for: generator/templates/simple/without-nvw/src/views/Home.vue

+24-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
</template>
3131
<%_ } _%>
3232
<%_ } _%>
33-
3433
<%_ if (!rootOptions.router) { _%>
3534
<%_ if (!usingTS) { _%>
3635
<%_ if (!usingNVW) { _%>
@@ -140,9 +139,6 @@
140139
<%_ } _%>
141140
<%_ } _%>
142141
<%_ } _%>
143-
144-
145-
146142
<!-- Add "scoped" attribute to limit CSS to this component only -->
147143
<%_ if (rootOptions.cssPreprocessor !== 'stylus') { _%>
148144
<style scoped<%-
@@ -152,17 +148,39 @@
152148
? 'scss'
153149
: rootOptions.cssPreprocessor
154150
}"`
155-
: ``
156-
%>>
151+
: `` %>>
152+
<%_ if (!usingNVW) { _%>
157153
img {
158154
height: 20%;
159155
width: 20%;
156+
display: block;
157+
margin: auto;
158+
margin-top: 4em;
160159
}
160+
<%_ } else { _%>
161+
<%# Is using NVW %>
162+
img {
163+
display: block;
164+
margin: auto;
165+
margin-top: 4em;
166+
}
167+
<%_ } _%>
161168
</style>
162169
<%_ } else { _%>
163170
<style scoped lang="stylus">
171+
<%_ if (!usingNVW) { _%>
164172
img
165173
height 20%
166174
width 20%
175+
display: block;
176+
margin: auto;
177+
margin-top: 4em;
178+
<%_ } else { _%>
179+
<%# Is using NVW %>
180+
img
181+
display: block;
182+
margin: auto;
183+
margin-top: 4em;
184+
<%_ } _%>
167185
</style>
168186
<%_ } _%>

Diff for: index.js

+53-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = (api, projectOptions) => {
3131
const appMode = platform === 'android' ? 'native' : platform === 'ios' ? 'native' : 'web';
3232
process.env.VUE_APP_MODE = appMode;
3333

34-
projectOptions.outputDir = path.join(api.service.context, appMode === 'web' ? 'platforms/web' : nsWebpack.getAppPath(platform, api.service.context));
34+
projectOptions.outputDir = path.join(api.service.context, appMode === 'web' ? 'dist' : nsWebpack.getAppPath(platform, api.service.context));
3535

3636
return appMode === 'web' ? webConfig(api, projectOptions, env, appMode, jsOrTs) : nativeConfig(api, projectOptions, env, platform, jsOrTs);
3737

@@ -567,7 +567,17 @@ const webConfig = (api, projectOptions, env, appMode, jsOrTs) => {
567567
}, config.module.rule('vue').uses.get('vue-loader').get('options')))
568568
.end()
569569

570+
const imageLoaderOptions = config.module.rule('images').uses.get('url-loader').get('options');
571+
imageLoaderOptions.fallback.options.name = 'assets/[name].[ext]';
572+
config.module.rules.delete('images')
570573

574+
config.module
575+
.rule('images')
576+
.test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
577+
.use('url-loader')
578+
.loader('url-loader')
579+
.options(imageLoaderOptions)
580+
.end()
571581

572582
// Define useful constants like TNS_WEBPACK
573583
config.plugin('define')
@@ -587,6 +597,48 @@ const webConfig = (api, projectOptions, env, appMode, jsOrTs) => {
587597
}])
588598
.end();
589599

600+
601+
// Copy assets to out dir. Add your own globs as needed.
602+
// if the project is native-only then we want to copy files
603+
// from the app directory and not the src directory as at
604+
// that point, the src directory should have been removed
605+
// when the plugin was originally invoked.
606+
config.plugin('copy-assets')
607+
.use(CopyWebpackPlugin, [
608+
[{
609+
from: {
610+
glob: path.resolve(api.resolve('src'), 'fonts/**')
611+
},
612+
to: path.join(projectOptions.outputDir, 'fonts/'),
613+
flatten: true
614+
},
615+
{
616+
from: {
617+
glob: path.resolve(api.resolve('src'), '**/*.jpg')
618+
},
619+
to: path.join(projectOptions.outputDir, 'assets'),
620+
flatten: true
621+
},
622+
{
623+
from: {
624+
glob: path.resolve(api.resolve('src'), '**/*.png')
625+
},
626+
to: path.join(projectOptions.outputDir, 'assets/'),
627+
flatten: true
628+
},
629+
{
630+
from: {
631+
glob: path.resolve(api.resolve('src'), 'assets/**/*')
632+
},
633+
to: path.join(projectOptions.outputDir, 'assets/'),
634+
flatten: true
635+
},
636+
], {
637+
//ignore: [`${path.relative(appPath, appResourcesFullPath)}/**`]
638+
}
639+
])
640+
.end();
641+
590642
// only adjust ts-loaders when we're using typescript in the project
591643
if (api.hasPlugin('typescript')) {
592644
const tsConfigOptions = config.module.rule('ts').uses.get('ts-loader').get('options');

0 commit comments

Comments
 (0)