maxparm / node-underscorify Goto Github PK
View Code? Open in Web Editor NEWUnderscore template pre-compiler for browserify
License: MIT License
Underscore template pre-compiler for browserify
License: MIT License
Isn't the point of precompiling the template to eliminate the runtime dependency on _?
Hi,
I followed the instructions and ran browserify -t node-underscorify content.js > content-bundle.js
but I get this error:
Error: module "./htmlparser" not found from "/Users/macuser/prj/static/node_modules/node-underscorify/node_modules/html-minifier/dist/htmlminifier.js"
at notFound (/usr/local/lib/node_modules/browserify/index.js:812:15)
at /usr/local/lib/node_modules/browserify/index.js:762:23
at /usr/local/lib/node_modules/browserify/node_modules/browser-resolve/index.js:185:24
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:35:22
at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:53:43)
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:59:22
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:16:47
at Object.oncomplete (fs.js:107:15)
And file (template) with node_modules
in its path is ignored by this transform. This may be an expected behavior in Browserify, but if that's the case I'd recommend documenting how to override it. Happy to help track this down later, but wanted to capture the information while I was thinking about it.
I'm attempting to pass templateSettings via grunt-browserify. My Gruntfile
looks like:
var template_opts = {
interpolate: /\{\{(.+?)\}\}/g,
escape: /\{-(.+?)\}/g,
evaluate: /<%(.+?)%>/g
};
module.exports = function( grunt ) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
spec: {
options: {
transform: [['node-underscorify', { templateSettings: template_opts }]],
browserifyOptions: {
debug: true
}
},
src: ['app/config.js','spec/**/*-spec.js'],
dest: 'spec/bundle.js'
}
}
});
grunt.loadNpmTasks( 'grunt-browserify' );
};
The compiled code doesn't use the specified delimiters.
I'm writing tests to run in node.js with mocha via jsdom (following this example) and I notice node-underscorify does not have an effect when the require()
is done outside of browserify (makes sense). Is there any way to run my require()
through node-underscorify outside of browserify? Or am I going about testing all wrong?
Could we catch the error that underscore throws, add the filename and rethrow it ?
Hi,
node-underscorify works like charm if underscore is set as global, but I need to use it locally for my modules, how can I setup underscore with shim when I require my templates ?
I tried something like that in my grunt file but unfortunately it doesn't work :
shim: {
underscore: {
path: 'vendor/underscore/underscore.js',
exports: '_'
},
templates: {
path: 'templates/**/*.html',
exports: null,
depends: {
underscore: 'underscore'
}
}
var _ = require('underscore');
var MyTemplates = require('templates/my-template.html');
Thanks.
Implement https://github.com/kangax/html-minifier to reduce size of compiled templates.
To ease contribution:
npm build
commandprepublish
scriptsdevDependencies
npm test
scriptThx!
I'm able to add node-underscorify to browserify's transform array via package.json, but it'd be great to also be able to specify the node-underscorify options here as well.
The html-minifier dependency is currently configured at 0.5.6.
New versions offer the ignoreCustomFragments
option which allows minification to occur correctly in some underscore template use-cases.
For example:
<select> <option value="1" <%= selected ? "selected" : "" %> ></option> </select>
Does not parse properly with html-minifier 0.5.6. Newer versions have added the ignoreCustomFragments
option which allows the minifier to ignore underscore template blocks. This can be used like so for the default underscore template syntax:
ignoreCustomFragments: [/<%[^%]*%>/]
After a change, the following output is produced
module.exports=function(obj){{var __t,__p="";Array.prototype.join}with(obj||{})__p+=module.exports=function(obj){{var __t,__p="";Array.prototype.join}with(obj||{})__p+=
It gets duplicated every time the watch fires
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.