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

grunt-importsrc

v0.1.2

Published

Import scripts and stylesheets paths from HTML files into your Gruntfile.

Downloads

1

Readme

grunt-importsrc

Import scripts and stylesheets paths from HTML files into your Gruntfile.
You can update an existing Grunt task like Uglify, mincss, etc. or just concatenate those imported files.

If you are bored of having to copy and paste file paths of scripts or stylesheets from your HTML to your Gruntfile, this plugin can help you.

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide, as it explains how to create a gruntfile as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:

$ npm install grunt-importsrc --save-dev

Importsrc task

This plugin is only compatible with Grunt >= 0.4.0.

Add importsrc to your Grunt file.

importsrc: {
  dist: {
    files: {
      'dist/index.html': 'src/index.html' // dest: source
    }
  }
}

Into your HTML file (here src/index.html), add importsrc sections with HTML comments.
You define importsrc options in those comments (see below for more informations).

Importsrc pattern

<!-- importsrc <option>:<path> -->  
[List of script or link tags]  
<!-- endimportsrc -->  

Options

update

Update paths of source files of an existing Grunt task.

Example with the uglify task ("list" format):

[Gruntfile.js]

importsrc: {
  dist: {
    files: {
      'dist/index.html': 'src/index.html'
    }
  }
},
uglify: {
  dist: {
    files: {
      'dist/app.js': [/* Source files will be updated by the importsrc task */]
    }
  },
  options: {
    mangle: true
  }
}
[src/index.html]

<!-- importsrc update:uglify.dist.files['dist/app.js'] -->
<script src="scripts/vendors/plugin.js"></script>
<script src="scripts/file-1.js"></script>
<script src="scripts/file-2.js"></script>
<!-- endimportsrc -->

Will render:

[dist/index.html]

<script src="app.js"></script>

Example with the mincss task ("full" format):

[Gruntfile.js]

importsrc: {
  dist: {
    files: {
      'dist/index.html': 'src/index.html'
    }
  }
},
mincss: {
  dist: {
    src: [/* Source files will be updated by the importsrc task */],
    dest: 'dist/app.css'
  }
}
[src/index.html]

<!-- importsrc update:mincss.dist.src -->
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endimportsrc -->

Will render:

[dist/index.html]

<script src="app.css"></script>

concat

Concatenates script or stylesheet files list.

Example:

<!-- importsrc concat:path/to/dest/file.(css|js) -->
[...]
<!-- endimportsrc -->
[src/index.html]

<!-- importsrc concat:dist/app.js -->
<script src="scripts/file-1.js"></script>
<script src="scripts/file-2.js"></script>
<!-- endimportsrc -->

Will render:

[dist/index.html]

<script src="app.js"></script>

dest

Change the dest file path of an existing Grunt task.

In case you need to change it.

Example:

[src/index.html]

<!-- 
  importsrc
  update:exotic.task.sources
  dest:dist/file.css -->
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endimportsrc -->

Will render:

[dist/index.html]

<script src="file.css"></script>

replace

Replace the generated file path.

By default, file paths are relative to the generated HTML file.
But you can change those paths with this option.

Example without the replace option:

[src/index.html]

<!-- importsrc
  update:update:mincss.dist.src -->
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endimportsrc -->

Will render:

[dist/index.html]

<script src="file.css"></script>

Example with the replace option:

[src/index.html]

<!-- importsrc
  update:update:mincss.dist.src
  replace:a/new/path/to/file.css -->
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endimportsrc -->

will render:

[dist/src]

<script src="a/new/path/to/file.css"></script>

Example

[Gruntfile.js]

grunt.initConfig({
  uglify: {
    example: {
      files: {
        'example/dist/min.js': []
      }
    }
  },
  mincss: {
    example: {
      files: {
        'example/dist/min.css': []
      }
    }
  },
  importsrc: {
    example: {
      files: {
        'example/dist/index.html': 'example/index.html'
      }
    }
  }
});

grunt.registerTask('example', ['importsrc:example', 'uglify:example', 'mincss:example']);

Execute the command grunt example and see example/ folder.

Release History

  • 02/2013 - 0.1.0 - Initial release

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

License

Copyright (c) 2013 Antoine Lehurt
Licensed under the MIT license.