NAME

Mojolicious::Plugin::Browserify - An Mojolicious plugin for assetpack+browserify

VERSION

0.06

DESCRIPTION

Mojolicious::Plugin::Browserify is a plugin that will register Mojolicious::Plugin::Browserify::Processor in Mojolicious::Plugin::AssetPack.

browserify is a JavaScript preprocessor which will allow you to use commonjs's require() in your JavaScript files. Here is an example JavaScript file, that use require() to pull in React:

var React = require('react');

module.exports = React.createClass({
  render: function() {
    return <div className="Bio"><p className="Bio-text">{this.props.text}</p></div>;
  }
});

SYNOPSIS

use Mojolicious::Lite;
plugin "Browserify" => {
  browserify_args => [-g => "reactify"],
  environment => app->mode, # default
  extensions => [qw( js jsx )], # default is "js"
};
app->asset("app.js" => "/js/main.js");

get "/app" => "app_js_inlined";
app->start;

__DATA__
@@ app_js_inlined.js.ep
%= asset "app.js" => {inline => 1}

Note! The SYNOPSIS require both "react" and "reactify" to be installed:

$ cd /home/projects/my-project
$ mojo browserify install react
$ mojo browserify install reactify

DEPENDENCIES

  • browserify

    This module require browserify to be installed. The node based application can either be installed system wide or locally to your project. To install it locally, you can use the browserify Mojolicious command:

    # same as "npm install browserify"
    $ mojo browserify install

    It is also possible to check installed versions using this command:

    $ mojo browserify version
  • uglifyjs

    uglifyjs is a really good minifier. The test react.t used to create a bundle that took 324K with JavaScript::Minifier::XS. With uglifyjs the same code takes 156K.

    What is the drawback? It takes a lot longer to run uglifyjs, but it's worth it, since it will only be called in production mode. Get it with this command:

    $ mojo browserify install uglify-js

METHODS

register

Used to register Mojolicious::Plugin::Browserify::Processor in the Mojolicious application.

COPYRIGHT AND LICENSE

Copyright (C) 2014, Jan Henning Thorsen

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org