-
-
Notifications
You must be signed in to change notification settings - Fork 1
Next Planning #1
Comments
Cool!This is pretty cool. IIRC, it was not possible in the previous
|
Is this still in the works? Could be achieved with vue-loader's custom blocks so vue-loader itself could still be used as-is and this library wouldn't have to reimplement the functionality? <!-- possible by using resourceQuery: /blockType=style-ios/ -->
<style-ios lang="sass"></style-ios>
<!-- or if resourceQuery can match on the query string (untested): -->
<style lang="sass?ios></style> The only problem that I foresee with this approach is that a native block should override a block that doesn't specify a platform. The loader should somehow keep track of what platform-specific blocks exist and omit any non-specific blocks they correspond to. Another option to allow for code sharing is to break out of the <!-- shared code (same file) -->
<template-ios src="./template.html"></template-ios>
<template-android src="./template.html"></template-android>
<!-- platform-specific code -->
<style-ios src="./style.ios.css"></style-ios>
<style-android src="./style.android.css"></style-android> However this is implemented if custom blocks are to be used, this library could expose an array of loader rules that could be merged into the consumer's webpack config. |
We would like to pre compile templates to improve nativescript app performance, and eliminate the need to parse and compile templates on the device.
The best case scenario for this loader is to be able to chain it with the official vue-loader, so we don't have to keep updating it from the official repo.
nativescript-vue-loader
->vue-loader
->other loaders
->build
This loader has to support (all optional) multiple templates (web/native/android/ios), multiple scripts (script - shared, script native, script web, script android, script ios) and multiple styles.
Based on the target platform we have to parse a
.vue
file (usingnativescript-vue-template-compiler
), and then build out another valid.vue
file that we pass on tovue-loader
to handle.Case 1: only targetting nativescript
The
.vue
file is as follows:First step (for all targets) is to parse the
.vue
file into block descriptors.build target:
android
First, we pick the template
<template android />
exists we use it<template>
(if exists)Second we pick the
<script>
,Third, if
<script android>
exists, we create a custom block<mixin>
Fourth, we pick the
<style>
block, and if<style android>
exists we merge it's contents into the<style>
block (taking care of cases where only<style android>
exists too!)Finally we assemble a new
.vue
file (in memory) as follows:Once the assemble phase is done, we are done with the
.vue
loader.build target:
ios
Same as
android
.We also need to create a loader for the
mixin
block as a runtime block.This is documented here: https://vue-loader.vuejs.org/en/configurations/custom-blocks.html#runtime-available-docs
pseudo code example:
Things to solve
We have to compile the templates using the
nativescript-template-compiler
, which I'm not sure we can do easily, at least not using the<template>
block. A custom block (like<nativescript-vue-template/>
) could take care of it, in a similar way as the<mixin>
block above.@yyx990803 posted a gist of an upcoming vue-loader version that simplifies how loaders are resolved, which inspired this write up. We can most likely use the features provided by the
next
version.https://gist.github.com/yyx990803/e0f4f1275841f4ce756b8c1ac1db76e9
The text was updated successfully, but these errors were encountered: