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

gulp-nette-basepath

v0.1.0

Published

Parse build blocks in Nette/Latte templates and resolves its Nette's basePath variable.

Downloads

95

Readme

gulp-nette-basepath

Plugin for gulp that parses build blocks of css/js files from Nette/Latte templates and resolves $basePath variable to real path.

This plugin is inspired by similar Grunt plugin - chemix/grunt-nette-basepath and based on gulp-useref plugin.

Getting started

Install the plugin with npm

npm install gulp-nette-basepath

Usage

The following example will parse the build blocks in the all Latte templates in app folder, replaces the basePath to ./www (relative to gulpfile.js location). The assets in build blocks will be concatenated and passed through the stream. Concatenated files will be written to their destination paths as defined in build blocks - this paths can also contain basePath.

var gulp = require('gulp'),
    basepath = require('gulp-nette-basepath');

gulp.task('default', function () {
	return gulp.src('app/**/*.html')
        .pipe(basepath({basePath: "./www"}))
        .pipe(gulp.dest('./'));
});

If you want to minify your assets or perform some other modification, you can use gulp-filter to handle specific types of assets.

var gulp = require('gulp'),
    basepath = require('gulp-nette-basepath'),
    filter = require('gulp-filter'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css');

gulp.task('html', function () {
    var jsFilter = filter('**/*.js');
    var cssFilter = filter('**/*.css');

    return gulp.src('app/**/*.latte')
        .pipe(basepath())
        .pipe(jsFilter)
        .pipe(uglify())
        .pipe(jsFilter.restore())
        .pipe(cssFilter)
        .pipe(minifyCss())
        .pipe(cssFilter.restore())
        .pipe(gulp.dest('./'));
});

Blocks are expressed as:

<!-- build:<type>(alternate search path) <path> -->
... HTML Markup, list of script / link tags.
<!-- endbuild -->
  • type: either js or css
  • alternate search path: (optional) By default the input files are relative to the treated file. Alternate search path allows one to change that
  • path: the file path of the optimized file, the target output

An example of this in completed form can be seen below:

<html>
    <head>
        <!-- build:css css/combined.css -->
        <link href="css/one.css" rel="stylesheet">
        <link href="css/two.css" rel="stylesheet">
        <!-- endbuild -->
    </head>
    <body>
        <!-- build:js scripts/combined.js -->
        <script type="text/javascript" src="scripts/one.js"></script>
        <script type="text/javascript" src="scripts/two.js"></script>
        <!-- endbuild -->
    </body>
</html>

This plugin does not support replacing the build blocks with combinied/mininified scripts and styles. If you are missing this feature, feel free to send pull request...

Instead I recommend using conditional switch between minified/non-minified in Latte template, same as Grunt basepath plugin uses. It is very nicely described on Planette

API

basepath(options)

Returns a stream with the concatenated asset files from the build blocks inside the template.

options.basePath

  • Type: string
  • Default: ./www

Sets string the {$basePath} is replaced with in paths. Defaults to www since its Nette default document root.

options.searchPath

  • Type: String or Array
  • Default: location of gulpfile.js

Specify the location to search for asset files, relative to the current working directory. Can be a string or array of strings.

options.verbose

  • Type: bool
  • Default: false

Shows more info of parsed files.

License

MIT