Coder Social home page Coder Social logo

johnpostlethwait / stringify Goto Github PK

View Code? Open in Web Editor NEW
136.0 4.0 27.0 257 KB

Browserify plugin to require() text files (templates) inside of your client-side JavaScript files.

Home Page: http://johnpostlethwait.github.com/stringify/

JavaScript 98.86% Makefile 0.44% HTML 0.70%

stringify's Introduction

Stringify

NOTE: I no longer actively maintain this package. I'd love to get PRs to keep it going though!

NPM Build Status

Browserify plugin to require() text files (such as HTML templates) inside of your client-side JavaScript files.

NOTE: Has not been tested on Node below version 4.0.0, and has been tested up to Node 8.1.3. Please report (or put a Pull Request up for) any bugs you may find.

Installation

npm install stringify

Usage

Browserify

Browserify Command Line

browserify -t [ stringify --extensions [.html .hbs] ] myfile.js

Browserify Middleware

var browserify = require('browserify'),
    stringify = require('stringify');

var bundle = browserify()
    .transform(stringify, {
      appliesTo: { includeExtensions: ['.hjs', '.html', '.whatever'] }
    })
    .add('my_app_main.js');

app.use(bundle);

NOTE: You MUST call this as I have above. The Browserify .transform() method HAS to plug this middleware in to Browserify BEFORE you add the entry point (your main client-side file) for Browserify.

Now, in your clientside files you can use require() as you would for JSON and JavaScript files, but include text files that have just been parsed into a JavaScript string:

var my_text = require('../path/to/my/text/file.txt');

console.log(my_text);

Gulp and Browserify

To incorporate stringify into a gulp build process using browserify, register stringify as a transform as follows:

var browserify = require('browserify'),
    source = require('vinyl-source-stream'),
    stringify = require('stringify');

gulp.task('js', function() {
  return browserify({ 'entries': ['src/main.js'], 'debug' : env !== 'dev' })
    .transform(stringify, {
        appliesTo: { includeExtensions: ['.html'] },
        minify: true
    })
    .bundle()
    .pipe(source('main.js')) // gives streaming vinyl file object
    .pipe(gulp.dest(paths.build));
});

NodeJS

Allows you to "stringify" your non-JS files using the NodeJS module system. Please only use Stringify this way in NodeJS (Read: Not the browser/Browserify!)

var stringify = require('stringify');

stringify.registerWithRequire({
  appliesTo: { includeExtensions: ['.txt', '.html'] },
  minify: true,
  minifyAppliesTo: {
    includeExtensions: ['.html']
  },
  minifyOptions: {
    // html-minifier options
  }
});

var myTextFile = require('./path/to/my/text/file.txt');

console.log(myTextFile); // prints the contents of file.

For NodeJS, the appliesTo configuration option only supports the includeExtensions option - see Including / Excluding Files section for further details.

Configuration

Loading Configuration from package.json

When package.json is found, configuration is loaded by finding a key in the package.json with the name "stringify" as your transform.

{
    "name": "myProject",
    "version": "1.0.0",
    ...
    "stringify": {
        "appliesTo": { "includeExtensions": [".html"] },
        "minify": true
    }
}

Or alternatively you can set the "stringify" key to be a .js or .json file:

{
    "name": "myProject",
    "version": "1.0.0",
    ...
    "stringify": "stringifyConfig.js"
}

And then configuration will be loaded from that file:

module.exports = {
    "appliesTo": { "includeExtensions": [".html"] },
    "minify": true
};

For more details about package.json configuration, see the Browserify Transform Tools configuration documentation.

Including / Excluding Files

The configuration option appliesTo is used to configure which files should be included or excluded. The default included extensions are:

['.html', '.htm', '.tmpl', '.tpl', '.hbs', '.text', '.txt']

The appliesTo should include exactly one of the following:

Option Description
.includeExtensions If this option is specified, then any file with an extension not in this list will skipped.
.excludeExtensions A list of extensions which will be skipped.
.files A list of paths, relative to the configuration file, of files which should be transformed. Only these files will be transformed.
.regex A regex or a list of regexes. If any regex matches the full path of the file, then the file will be processed, otherwise not.

For more details about the appliesTo configuration property, see the Browserify Transform Tools configuration documentation.

Minification

By default, files will not get minified - setting minify configuration option to true will enable this.

The minifyAppliesTo configuration option allows files to be included or excluded from the minifier in a similar way to appliesTo (see Including / Excluding Files section for more details).

The default included file extensions are:

['.html', '.htm', '.tmpl', '.tpl', '.hbs']

The options set in the minifyOptions configuration option are passed through to html-minifier (for more informations or to override those options, please go to html-minifier github).

The default value of minifyOptions is:

{
  removeComments: true,
  removeCommentsFromCDATA: true,
  removeCDATASectionsFromCDATA: true,
  collapseWhitespace: true,
  conservativeCollapse: false,
  preserveLineBreaks: false,
  collapseBooleanAttributes: false,
  removeAttributeQuotes: true,
  removeRedundantAttributes: false,
  useShortDoctype: false,
  removeEmptyAttributes: false,
  removeScriptTypeAttributes: false,
  removeStyleLinkTypeAttributes: false,
  removeOptionalTags: false,
  removeIgnored: false,
  removeEmptyElements: false,
  lint: false,
  keepClosingSlash: false,
  caseSensitive: false,
  minifyJS: false,
  minifyCSS: false,
  minifyURLs: false
}

If you require an HTML file and you want to minify the requested string, you can configure Stringify to do it:

stringify({
  appliesTo: { includeExtensions: ['.txt', '.html'] },
  minify: true,
  minifyAppliesTo: {
    includeExtensions: ['.html']
  },
  minifyOptions: {
    // html-minifier options
  }
})

Realistic Example/Use-Case

The reason I created this was to get string versions of my Handlebars templates required in to my client-side JavaScript. You can theoretically use this for any templating parser though.

Here is how that is done:

application.js:

var browserify = require('browserify'),
    stringify = require('stringify');

var bundle = browserify()
    .transform(stringify, {
      appliesTo: { includeExtensions: ['.hbs', '.handlebars'] }
    })
    .addEntry('my_app_main.js');

app.use(bundle);

my_app_main.js:

var Handlebars = require('handlebars'),
    template = require('my/template/path.hbs'),
    data = {
      "json_data": "This is my string!"
    };

var hbs_template = Handlebars.compile(template);

// Now I can use hbs_template like I would anywhere else, passing it data and getting constructed HTML back.
var constructed_template = hbs_template(data);

/*
  Now 'constructed_template' is ready to be appended to the DOM in the page!
  The result of it should be:

  <p>This is my string!</p>
*/

my/template/path.hbs:

<p>{{ json_data }}</p>

Contributing

If you would like to contribute code, please do the following:

  1. Fork this repository and make your changes.
  2. Write tests for any new functionality. If you are fixing a bug that tests did not cover, please make a test that reproduces the bug.
  3. Add your name to the "contributors" section in the package.json file.
  4. Squash all of your commits into a single commit via git rebase -i.
  5. Run the tests by running npm install && make test from the source directory.
  6. Assuming those pass, send the Pull Request off to me for review!

Please do not iterate the package.json version number – I will do that myself when I publish it to NPM.

Style-Guide

Please follow this simple style-guide for all code contributions:

  • Indent using spaces.
  • camelCase all callables.
  • Use semi-colons.
  • Place a space after a conditional or function name, and its conditions/arguments. function (...) {...}

stringify's People

Contributors

codeviking avatar dackmin avatar everyonesdesign avatar holic avatar livoras avatar matthewdunsdon avatar samsy avatar sebastiendavid avatar sebdeckers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stringify's Issues

Error: Cannot find module './htmlparser'

Hello,

I have an error when i watchify:

Error: Cannot find module './htmlparser' from '/home/projects/cloud/node_modules/stringify/node_modules/html-minifier/dist'

Have you got an idea ?

Security vulnerability - update html-minifier

→ nsp check
(+) 1 vulnerabilities found
┌───────────────┬──────────────────────────────────────────────────────────────────┐
│               │ Regular Expression Denial of Service                             │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ Name          │ uglify-js                                                        │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ Installed     │ 2.4.24                                                           │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ Vulnerable    │ <2.6.0                                                           │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ Patched       │ >=2.6.0                                                          │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ Path          │ [email protected] > [email protected] > [email protected]         │
├───────────────┼──────────────────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/48                            │
└───────────────┴──────────────────────────────────────────────────────────────────┘

Update html-minifier to v1.5.0 (at least)

NodeSecurity recently started to yell that stringify has a low level vulnerability because it uses html-minifier, which depends on cli#v0.11.x (responsible for the flaw).

This minor security flaw has been patched in cli#v1.x.x. However, html-minifier doesn't use cli anymore starting with v1.5.0.

Is it possible to update html-minifier to at least v1.5.0, and if it doesn't break anything, to v3.5.2 ?

Cheers !

Doesn't work with backticks?

I'm trying to use this with gulp to require markdown files as strings, but I'm getting this sort of error:

(function (exports, require, module, __filename, __dirname) { ```foo bar baz
^
SyntaxError: Unexpected token ILLEGAL

I'd like require to import html files as template strings

it think it would be really cool to be able to do something like

template.html

<h1>Stringify is ${word}</h1>

and then in javascript:

var word = 'Awesome'
$('body').html(require('template.html'))

Has anyone figured out how to do this yet?

Tests are failing

→ gulp test
[11:14:25] Using gulpfile ~/www/stringify/gulpfile.js
[11:14:25] Starting 'test'...
[11:14:25] Finished 'test' after 22 ms


  the "getExtensions" function
    when passed no options argument
      ✓ should have returned a non-empty array 
      ✓ should have returned the correct extensions 
    when passed an array of file-extensions as an options argument
      ✓ should have returned a non-empty array 
      ✓ should have returned the correct extensions 
    when passed an object with an "extensions" array property as an options argument
      ✓ should have returned a non-empty array 
      ✓ should have returned the correct extensions 

  the "getMinifierOptions" function
    ✓ should have returned default configuration for minifier 
    ✓ should have returned overriden configuration for minifier 

  the "hasStringifiableExtension" function
    when the filename has an extension in the array
      ✓ should have returned "true" 
    when the filename does not have an extension
      ✓ should have returned "false" 

  when the module is required
    ✓ should return a function 
    ✓ should have a method "registerWithRequire" 

  when the module called
    with no options
      ✓ should return a factory function named "browserifyTransform" 
      when the returned function is called with a valid file path
        ✓ should return a Stream object 
    with options as first argument
xxxxxxxxxxxxxxxxxxxxxxxxxxx
      ✓ should return a function named "browserifyTransform" 
      1) should respond to input with the given options
    with a HTML file as first argument
      ✓ should return a Stream object 
      2) should respond to input
    with an unknown file as first argument
      ✓ should return a Stream object 
      ✓ should respond without transformation 

  the "minify" function
    ✓ should return a function 
    ✓ should have default minifier extensions 
    ✓ should minify html content 
    ✓ should not minify html content because minification is not requested 
    ✓ should not minify html content because extension is not supported 

  the "registerWithRequire" function
    ✓ should allow me to require "./file_fixture.txt" as strings 

  the "stringify" function
    ✓ should have returned a string 
    ✓ should begin with module.exports = " 
    ✓ should have perserved newline characters 
    ✓ should have escaped the double-quotes 


  28 passing (20ms)
  2 failing

  1) when the module called with options as first argument should respond to input with the given options:
     TypeError: buf.copy is not a function
      at Function.Buffer.concat (buffer.js:237:9)
      at Stream.end (/home/alessio/www/stringify/src/stringify.js:200:29)
      at _end (/home/alessio/www/stringify/node_modules/through/index.js:65:9)
      at Stream.stream.end (/home/alessio/www/stringify/node_modules/through/index.js:74:5)
      at next (/home/alessio/www/stringify/test/main.js:17:12)
      at write (/home/alessio/www/stringify/test/main.js:19:3)
      at Context.<anonymous> (/home/alessio/www/stringify/test/main.js:101:7)
      at callFn (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:250:21)
      at Test.Runnable.run (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:243:7)
      at Runner.runTest (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:373:10)

  2) when the module called with a HTML file as first argument should respond to input:
     TypeError: buf.copy is not a function
      at Function.Buffer.concat (buffer.js:237:9)
      at Stream.end (/home/alessio/www/stringify/src/stringify.js:200:29)
      at _end (/home/alessio/www/stringify/node_modules/through/index.js:65:9)
      at Stream.stream.end (/home/alessio/www/stringify/node_modules/through/index.js:74:5)
      at next (/home/alessio/www/stringify/test/main.js:17:12)
      at write (/home/alessio/www/stringify/test/main.js:19:3)
      at Context.<anonymous> (/home/alessio/www/stringify/test/main.js:135:7)
      at callFn (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:250:21)
      at Test.Runnable.run (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:243:7)
      at Runner.runTest (/home/alessio/www/stringify/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:373:10)




events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: 2 tests failed.

 alessio: /home/alessio/www/stringify git:master
→ node -v && npm -v
v5.1.1
3.5.3

Unable to pass `customAttrCollapse` option to `html-minifier`

browserify app.js --debug -t [ stringify --minify --minifyOptions [ --customAttrCollapse /ng-class/ ] --extensions [ .html ] ]

Will not work because the customAttrCollapse option is expected to be a regexp. html-minifier's command line interface will parse this argument into a regexp, but stringify does not.

Note that I get the same result with -t [ stringify --minify --minifier [ --options [ --customAttrCollapse /ng-class/ ] ] ]

4.0.0 does not work from command line

I have a simple js file in.js:

require('./in.html');

and in.html:

<h1>Hello World!</h1>

When I run browserify in.js -d -t stringify -o out.js I get the following error:

<h1>Hello World!</h1>
^
ParseError: Unexpected token

This has something to do with the new Stream2 stuff, since [email protected] works just fine. I've tested this with [email protected] - 13.0.0 with no success.

Could not compile

file.txt:

ddd"

code:

browserify.transform(stringify(['.txt']));

error:
ParseError: Unterminated string constant

If I remove " from file.txt it works..

String is not correctly reconstructed when it uses quotes

If you process a text file which includes both single and double quotes, the result of running through the stringify/require process has escaped quotes in it.

Input:
<div attrib="something containing 'quotes'">

Output
<div attrib="something containing \'quotes\'">

I can see why this happens, but any suggestions on how to fix? Thanks!

Passing extensions in via command line

Sorry if this is the wrong place to put this but having trouble trying to figure out what is going on (it may well be I'm making a mistake)

I'm trying to pass extensions in via the command line like so:

browserify -t [ stringify --extensions ['.hjs', '.html', '.whatever'] ]

But when I do this i get this error:

79: extensions = extensions.map(function (ext) {
                          ^
TypeError: undefined is not a function

It is entirely plausible that I am passing in these options incorrectly but I can't find any documentation on the right way to pass them in via command line. (I have also tried the extensions without the square brackets, without commas and without inverted commas)

relatives directories??

i use stringify for compile templates very well, but in the compiled file, browserify save the relatives directories with the name, who can change that?

for example:
template: require('../../../template.users.view.html')

browserify generate the colection like this
{"../../../../template.users.view.html":118}

who can remove the './././'???

Update README to be clearer for usage with NPM Scripts.

I changed from gulp to npm-scripts and now --conservativeCollapse option don't work anymore
(maybe the stringify version updated in the process)

This is the command i'm using (in windows) :

browserify --no-bundle-external --transform browserify-ngannotate --transform [ stringify --extensions [.html] --minify [ --collapseWhitespace --preserveLineBreaks --conservativeCollapse --removeComments --removeAttributeQuotes --removeTagWhitespace ] ] --debug --plugin [ minifyify --map app.min.js.map --output app.min.js.map ] app.js --outfile app.min.js

Is it stringify bug or something wrong in my command syntax?

thanks

Usage via grunt

Hello,

I am sorry to open this as an issue, but I didn't find a forum where this could be posted.
I would like to include stringify in my grunt task.
Is there any way to do that?

Thanks in advance

not minifying file in grunt

I'm using the grunt browserify plugin which shouldnt relaly matter. but I'm adding a transform like this:

    configure: (browserify) ->
      # transpile coffeescript to javascript
      browserify.transform "coffeeify"
      # load any static files (template cacheing)!
      browserify.transform stringify
        extensions: ['.html']
        minify: true
        minifier:
          extensions: ['.html']
          options: {}

it works, but it doesnt minify the html. any ideas?

lint is not working

i use this command to build:

browserify -v --no-bundle-external --t eslintify --t browserify-ngannotate --t imgurify --t [ stringify --extensions [.html] --minify --minifier [ --options [ --lint --compress-path --collapseWhitespace --preserveLineBreaks --conservativeCollapse --removeComments --removeAttributeQuotes --removeTagWhitespace ] ] ] --debug --plugin [ minifyify --map app.min.js.map --output app.min.js.map ] app.js --outfile app.min.js

without --lint its working fine but with it its says:

TypeError: lint.testElement is not a function (while stringify was processing C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\components\dashboard\dashboard.html) while parsing file: C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\components\dashboard\dashboard.html
at Object.HTMLParser.start (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\html-minifier\src\htmlminifier.js:662:16)
at parseStartTag (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\html-minifier\src\htmlparser.js:384:17)
at String.replace (native)
at new global.HTMLParser (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\html-minifier\src\htmlparser.js:239:22)
at Object.minify (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\html-minifier\src\htmlminifier.js:619:5)
at minify (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\src\stringify.js:157:27)
at Stream.transformFn (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\src\stringify.js:219:24)
at Stream.end (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\browserify-transform-tools\lib\transformTools.js:108:30)
at _end (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\browserify-transform-tools\node_modules\through\index.js:65:9)
at Stream.stream.end (C:\SVN\Java\ts\magnus\manager\mgm-web\src\main\webapp\node_modules\stringify\node_modules\browserify-transform-tools\node_modules\through\index.js:74:5)

Error: path must be a string

Sort of unhelpful error message. I am using it in package.json, like this:

  "scripts": {
    "js": "browserify index.js -x ractive --standalone gauge -o dist/ractive-gauge.js && uglifyjs dist/ractive-gauge.js -o dist/ractive-gauge.min.js"
  },
  "browserify": {
    "transform": [
      "stringify", {
        "extensions": ".svg"
      }
    ]},
  "devDependencies": {
    "browserify": "^8.1.3",
    "stringify": "^3.1.0",
    "uglify-js": "^2.4.16"
  },

I get this error:

Error: path must be a string
    at .../ractive-gauge/node_modules/browserify/node_modules/module-deps/node_modules/resolve/lib/async.js:16:16
    at process._tickCallback (node.js:355:11)

It works fine if I remove text-requires & the transform stuff.

Stringify from node_modules not working

If node_modules/abc/file.txt contains the string "123" and I require('abc/file.txt') stringify will create a block like this in the browserify output:

13:[function(require,module,exports){
123
},{}]

instead of something like this:

13:[function(require,module,exports){
module.exports = "123"
},{}]

Can't require files from node_modules

For some reason, I when I require files in ./node_modules, I get:

events.js:72
        throw er; // Unhandled 'error' event
              ^
SyntaxError: Unexpected token

Root or other directories seem to work fine. Here's my gulpfile.js:

'use strict';

var gulp = require('gulp');

var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');

var browserify = require('browserify');
var stringify = require('stringify');

gulp.task('svg', function(){
    var bundle = browserify()
    .transform(stringify(['.text', '.html', '.svg']))
    .add('./svg.js');

    return bundle.bundle()
    .pipe(source('svg_bundle.js'))
    .pipe(buffer())
    .pipe(gulp.dest('./'));
});

I'm running gulp svg to test this.

Here's ./svg.js:

var svg = require('./test.svg'); //works
var svg2 = require('./node_modules/test.svg'); //breaks

Here's the contents of test.svg (both):

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5.5 7.5h2v-2H9v2h2V9H9v2H7.5V9h-2V7.5zM19 19H5L19 5v14zm-2-2v-1.5h-5V17h5z"/></svg>

Here's ls -l for both of those files:

-rw-r--r-- 1 ubuntu ubuntu 252 Nov 14 09:53 test.svg

-rw-r--r-- 1 ubuntu ubuntu 252 Nov 14 09:53 node_modules/test.svg

Here's the successful output to ./svg_bundle.js from just ./test.svg:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var svg = require('./test.svg'); //works
//var svg2 = require('./node_modules/test.svg'); //breaks

},{"./test.svg":2}],2:[function(require,module,exports){
module.exports = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5.5 7.5h2v-2H9v2h2V9H9v2H7.5V9h-2V7.5zM19 19H5L19 5v14zm-2-2v-1.5h-5V17h5z\"/></svg>";

},{}]},{},[1]);

Anything I'm missing?

Use with dynamic modules

There is support for using like this:

require('./views/' + someVar + '.tpl.html');

I am getting this error:
Cannot find module './views/article.tpl.html'

Can't get it to work (ParseError: Unexpected token)

Hi,

Your lib is exactly what I was looking for but sadly, I can't get it to work.

I think that Browserify is trying to parse my .hbs files like a js file so I get a "ParseError: Unexpected token".

I use it via a node task which does the following:

var entryPath = 'MY_ENTRY_PATH';
var bundlePath = 'MY_BUNDLE_PATH';

browserify({
    debug: true,
})
.transform(stringify({
    extensions: [ '.hbs' ],
    minify: true
}))
.add(entryPath)
.bundle(function(err) {
    if (!err) {
        console.log('File has been saved.');
    }
})
// Write the stream in a real file
.pipe(fs.createWriteStream(bundlePath));

Am I doing something wrong ?
Thanks a lot

Stringify adding &#65279 to beginning of html

I modified the source to stop the 'ZERO WIDTH NO-BREAK SPACE' character from appearing at the beginning of all the html. I am using browserify and stringify together.

function stringify(content) {
content = content.replace(/^\uFEFF/, '');
return 'module.exports = ' + JSON.stringify(content) + ';\n';
}

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.