Skip to content

Instantly share code, notes, and snippets.

@xgvargas
Last active July 27, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgvargas/67d86c11a0b9e806dc261002197bfc76 to your computer and use it in GitHub Desktop.
Save xgvargas/67d86c11a0b9e806dc261002197bfc76 to your computer and use it in GitHub Desktop.
Starting with Nativescript and seting up to use Coffeescript, Pug and Stylus

Nativescript

The standard version of Nativescript uses XML, JS and SCSS, no matter the selected framework.

In my case I like to use Pug, Coffeescript and Stylus with VueJS.

Bellow is the process to configure the CLI to use this combination:

# while nativescript uses NPM internally I like to use Yarn, so my global is installed with it.
# Use `npm install -g nativescript` if you prefer to.
yarn global add nativescript

# create your app using VueJS, use any appID you want
tns create MyApp --vue --appid com.domain.myapp

cd MyApp

# install our new development dependencies
# since internally nativescript uses NPM always, here is a good idea to use it too
# instead of yarn (if is your case)
npm install -D stylus stylus-loader coffeescript coffee-loader pug pug-plain-loader

Edit webpack.config.js and add following block to its end just before return config.

    //^^^^^ original webpack content  ^^^^^^

    config.resolve.extensions.push( 'styl', 'coffee' );
    config.module.rules.push(
        {
            test: /\.coffee$/, use: [ 'babel-loader', 'coffee-loader', ],
        },
        {
            test: /\.styl(us)?$/,
            use: [
                'nativescript-dev-webpack/style-hot-loader',
                'nativescript-dev-webpack/apply-css-loader.js',
                { loader: "css-loader", options: { url: false } },
                "stylus-loader",
            ],
        },
        {
            test: /\.pug$/, loader: 'pug-plain-loader'
        },
    );

    // \/\/\/\/ original content \/\/\/\/

    return config;
};

This changes will not break the original configuration, so the original code will run normally, even it's using XML, JS and SCSS, but you can create new .vue files using following template:

<template lang="pug">
.

</template>


<style lang="stylus">
// .
</style>


<script lang="coffee">
module.exports =
    name: ''
    # props: []
    # data: ->
    # computed:
    # watch:
    #    '$route': (to, from) ->
    # components:
    # beforeRouteEnter: (to, from, next) ->
    # beforeRouteLeave: (to, from, next) ->
    # created: ->
    # mounted: ->
    #     @$nextTick ->
    # destroyed: ->
    # beforeDestroy: ->
    # methods:

</script>

Finally you should be able to preview your new app

tnx preview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment