GithubHelp home page GithubHelp logo

ionic-team / usemin-lib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nelsyeung/usemin-cli

0.0 10.0 0.0 121 KB

Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views)

License: MIT License

JavaScript 81.52% HTML 18.48%

usemin-lib's Introduction

usemin-lib

Library version of usemin. For purists, those who doesn't use build tools like Grunt and Gulp, but just use NPM as their build tool.

Getting started

To use this now, install with this command:

npm install usemin-lib

From GitHub

git clone https://github.com/driftyco/usemin-lib.git
cd usemin-lib
npm install
npm link

Usage

var fs = require('fs'), path = require('path');
var indexHtmlFilePath = path.join('./', 'index.html');
var useminLib = require('usemin-lib');
var content = fs.readFileSync(indexHtmlFilePath).toString();
var blocks = useminLib.getBlocks(indexHtmlFilePath, content, true /* removeLivereloadBool */);
var process = useminLib.processBlocks(blocks, './www/dist/index.html' /* destDir */);
var output = useminLib.getHTML(content, blocks, true /* htmlminBool */);
console.log('minified stuffs:', output);

Example HTML

<!-- build:css css/main.js -->
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/modules.css">
<!-- endbuild -->

<!-- build:js js/main.js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<!-- endbuild -->

<!-- build:js js/main.js -->
<script defer async src="js/app.js"></script>
<script defer async src="js/controllers.js"></script>
<!-- endbuild -->

<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>

Running the command with --rmlr true will output:

<link rel="stylesheet" href="css/main.js">
<script src="js/main.js"></script>
<script defer async src="js/main.js"></script>

License

MIT license

usemin-lib's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.