├── .eslintrc ├── .gitignore ├── README.md ├── index.js ├── npm-shrinkwrap.json └── package.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "node": true 6 | }, 7 | "ecmaFeatures": { 8 | "modules": true 9 | }, 10 | "rules": { 11 | "quotes": [0], 12 | "no-new": [0], 13 | "no-mixed-requires": [0, false], 14 | "no-loop-func": [0], 15 | "no-alert": [0], 16 | "eol-last": [0], 17 | "no-unused-vars": [2, {"vars": "all", "args": "none"}], 18 | "no-unused-expressions": [0] 19 | }, 20 | "globals": { 21 | "ga": false 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # template-string-loader 2 | Webpack [ES6 Template String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings) Loader 3 | 4 | ## Installation 5 | 6 | `npm install template-string-loader` 7 | 8 | ## Usage 9 | You will need to use this with the babel loader or some other ES6 loader that supports template strings. 10 | 11 | ``` javascript 12 | var template = require("babel!template-string!./file.html")({data: '123'}); 13 | ``` 14 | 15 | Example template: 16 | 17 | ``` html 18 | 19 |
${scope.data}
20 | ``` 21 | 22 | The loader returns a function like below. Call the function with the data you want to pass to the template. That data is available on the scope param: 23 | 24 | ``` javascript 25 | module.exports = function(scope){ 26 | return `
${scope.data}
`; 27 | } 28 | ``` 29 | 30 | Result: 31 | 32 | ``` html 33 |
123
34 | ``` 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Brad Benvenuti @bradbenvenuti 4 | */ 5 | module.exports = function(content) { 6 | this.cacheable && this.cacheable(); 7 | this.value = content; 8 | return 'module.exports=function(scope){ return `' + content + '`};'; 9 | }; 10 | -------------------------------------------------------------------------------- /npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "template-string-loader", 3 | "version": "0.0.4", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "template-string-loader", 3 | "version": "0.0.4", 4 | "author": "Brad Benvenuti", 5 | "description": "ES6 template string loader module for webpack", 6 | "repository": { 7 | "type": "git", 8 | "url": "git@github.com:bradbenvenuti/template-string-loader.git" 9 | }, 10 | "license": "MIT", 11 | "bugs": { 12 | "url": "https://github.com/bradbenvenuti/template-string-loader/issues" 13 | }, 14 | "homepage": "https://github.com/bradbenvenuti/template-string-loader", 15 | "main": "index.js", 16 | "scripts": { 17 | "test": "echo \"Error: no test specified\" && exit 1" 18 | } 19 | } 20 | --------------------------------------------------------------------------------