npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-native-scripts

v0.3.1

Published

Compile Vue Native components to React Native

Downloads

235

Readme

vue-native-scripts

This package is auto-generated. For pull requests please work with src/platforms/vue-native/scripts/index.js.

Compile and transform Vue components to React Native.

Find the vue-native-core repository here.

For the official documentation, visit this website.

Usage

Vue Native CLI is the recommended way to setup a new Vue Native project. However, if you wish to setup a project from scratch, use the following steps after setting up a React Native / Expo project.

Step 1: Install

The following packages are required as runtime dependencies by Vue Native:

During development, another package is required to transpile Vue Native component files (with .vue extensions) into JS:

To install them, run the following commands in your project directory

$ npm install --save vue-native-core vue-native-helper
$ npm install --save-dev vue-native-scripts

Step 2: Configure the React Native bundler

The Metro bundler is used by React Native to generate app bundles. It can be configured using a metro.config.js file. Add the following to your metro.config.js (make one to your project's root if you don't have one already):

const { getDefaultConfig } = require("metro-config");

module.exports = (async () => {
  const {
    resolver: { sourceExts }
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve("./vueTransformerPlugin.js"),
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: false,
        },
      })
    },
    resolver: {
      sourceExts: [...sourceExts, "vue"]
    }
  };
})();

The babelTransformPath property above takes the path to the transformer you wish to use. In our case, we need to create a vueTransformerPlugin.js file to the project's root and specify supported extensions:

// For React Native version 0.59 or later
var upstreamTransformer = require("metro-react-native-babel-transformer");

// You will need to use different transformers for different React Native versions
// However, versions older than v0.59 are no longer supported by Vue Native

// For React Native version 0.56 - 0.58
// var upstreamTransformer = require("metro/src/reactNativeTransformer");

// For React Native version 0.52 - 0.55
// var upstreamTransformer = require("metro/src/transformer");

// For React Native version 0.47 - 0.51
// var upstreamTransformer = require("metro-bundler/src/transformer");

// For React Native version 0.46
// var upstreamTransformer = require("metro-bundler/build/transformer");

var vueNaiveScripts = require("vue-native-scripts");
var vueExtensions = ["vue"]; // <-- Add other extensions if needed.

module.exports.transform = function({ src, filename, options }) {
  if (vueExtensions.some(ext => filename.endsWith("." + ext))) {
    return vueNaiveScripts.transform({ src, filename, options });
  }
  return upstreamTransformer.transform({ src, filename, options });
};

This file conditionally transforms files based on their extensions. vue-native-scripts is used for .vue files, while the stock React Native Babel transformer is used for other (JS) files.

Using Vue Native components and .vue files

In the React Native application, you can simply import your Vue components as follows

import VueComponent from './VueComponent.vue'

There should be a file named VueComponent.vue in the corresponding folder; the transformer parses this file and sends it to the React Native bundler.