Giter Site home page Giter Site logo

super-bundler's Introduction

#super bundler

super-bundler 可以将多个文件,如 css, js, template 打包入 HTML 中。 相比其它前端模块化工具,它配置更加简单,且有很强的扩展性,尤其适合 SPA 这类不需要动态渲染 HTML 的 web 应用。

##Example

index.js

var logger = require('./logger');
logger.log();

logger.js

module.exports = {
    log: function(){
        console.log('hello world');
    }
};

index.less

@blue: #246AFF;
h1{
    color: @blue;
}

index.html

<!doctype html>
<html>
    <head>
    <bundle src="index.less" type="less"/>
    <bundle src="index.js" type="js"/>
    </head>
    <body>
        <h1>Super Pack</h1> 
    </body>
</html>

example.js

var Bundle = require('super-bundle'),
    fs = require('fs');

var options = {};

var bundle = new Bundle(options);

fs.readFile('./index.html', function(err,content){
    if(err) return console.error(err);
    
    bundle.exec('./index.html', content.toString(), function(err, content){
    
    if(err)return console.error(err);
    console.log(content);
         
    })
})
$ node example.js

output

<!doctype html>
<html>
    <head>
    <style type="text/css">h1 {
  color: #246AFF;
}
</style>
    <script type="text/javascript" id="$$$require">
;(function(global){var ms=[];function r(i){return ms[i]};r.ms=ms;global.$$$require=r;})("undefined"==typeof module?window:global);
</script><script type="text/javascript" id="./logger">
;(function(){var m={exports: {}};(function(require, module, exports){
module.exports = {
    log:function(){
        console.log('hello world');
    }
}


})($$$require,m,m.exports);$$$require.ms.push(m.exports||{});})();
</script><script type="text/javascript" id="index.js">
;(function(){var m={exports: {}};(function(require, module, exports){
var logger = require(0);
logger.log();


})($$$require,m,m.exports);$$$require.ms.push(m.exports||{});})();
</script>
    </head>
    <body>
        <h1>Super Pack</h1> 
    </body>
</html>

如果你设置了options.uglify = true,那么输出的结果将会全部被 uglify

<!doctype html><html><head><style type="text/css">h1 {color: #246AFF;}</style>style><script type="text/javascript" id="$$$require">
!function(n){function e(n){return o[n]}var o=[];e.ms=o,n.$$$require=e}("undefined"==typeof module?window:global);
</script>script><script type="text/javascript" id="./logger">
!function(){var o={exports:{}};!function(o,e,r){e.exports={log:function(){console.log("hello world")}}}($$$require,o,o.exports),$$$require.ms.push(o.exports||{})}();
</script>script><script type="text/javascript" id="index.js">
!function(){var r={exports:{}};!function(r,e,o){var $=r(0);$.log()}($$$require,r,r.exports),$$$require.ms.push(r.exports||{})}();
</script>script></head>head><body><h1>Super Pack</h1>h1> </body>body></html>html>

##options

  • uglify 是否 uglify
  • expandAll 展开所有的 bundle, (link="true" 的标签默认不会被展开)
  • paths 寻找文件的路径

super-bundler's People

Stargazers

Austin Lee avatar Bryan Yang avatar

Watchers

James Cloos avatar Eric Time 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.