Skip to content

Instantly share code, notes, and snippets.

@rwhitmire
Last active August 29, 2015 14:14
Show Gist options
  • Save rwhitmire/9cd371e748465e5915c3 to your computer and use it in GitHub Desktop.
Save rwhitmire/9cd371e748465e5915c3 to your computer and use it in GitHub Desktop.
grunt-sails-linker ideas

continuation from: https://gist.github.com/mikermcneil/f1294b34f89f9ee9f392

Problems I ran into

After spending a decent amount of time working on a new approach for bundling and automatically injecting references into the HTML, a few problems started presenting themselves. First of all, declaring glob patterns inline with a tag limits our flexibility. It makes it difficult (impossible?) to bundle files from multiple directories. It also becomes difficult (impossible?) to specify the order of scripts if needed.

Also, injecting files from pipeline.js becomes difficult as we don't really know where to put files if multiple blocks exist.

Potential solution

I spend a fair amount of time working in ASP.NET, and I think we can possibly borrow some of their ideas for bundling and injecting scripts onto the page. I think we could repurpose pipleine.js - possibly rename it bundles.js - to contain data about resource bundles. See code below for examples.

var scriptBundles = {
vendor: {
'vendor/jquery/jquery.js',
'vendor/**/*.js'
},
main: {
'js/app.js',
'js/**/*.js'
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<!-- bundle name="vendor" type="js" -->
<!-- /bundle -->
<!-- bundle name="main" type="js" -->
<!-- /bundle -->
</body>
</html>
@mikermcneil
Copy link

@rwhitmire great point- and your solution is perfect. Sorry about my slow response

@rwhitmire
Copy link
Author

i'm sure this will need some tweaking, but it's a start: https://github.com/rwhitmire/grunt-bundler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment