Skip to content

Commit

Permalink
Clean-up and upgrade to CanJS3
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Adamczak committed Jun 27, 2017
1 parent 623e74c commit e61b351
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 121 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
[![dependencies](https://img.shields.io/david/macku/can-stache-loader.svg)](https://david-dm.org/macku/can-stache-loader)
[![dev dependencies](https://img.shields.io/david/dev/macku/can-stache-loader.svg)](https://david-dm.org/macku/can-stache-loader?type=dev)

<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
</div>

# CanJS Stache template loader for webpack

Compiles [CanJS Stache](https://github.com/canjs/can-stache) templates with [can-view-parser](https://github.com/canjs/can-view-parser) and allows to load them with [webpack](https://webpack.github.io/)
Expand All @@ -28,6 +35,8 @@ yarn add can-stache-loader

### Configure webpack 2+

**webpack.config.js**

```js
{
module: {
Expand All @@ -46,7 +55,8 @@ yarn add can-stache-loader
### Import stache templates in your [CanJS](https://canjs.com/) project

```js
const tpl = require('./template.stache');
import tpl from './template.stache';

const html = tpl({
foo: 'bar'
});
Expand Down
47 changes: 0 additions & 47 deletions clean-line-endings.js

This file was deleted.

14 changes: 5 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
const getIntermediateAndImports = require('./intermediate_and_imports');
// const getIntermediateAndImports = require('can-stache/src/intermediate_and_imports');
// const getIntermediateAndImports = require('can/dist/cjs/view/stache/intermediate_and_imports');

const getIntermediateAndImports = require('can-stache/src/intermediate_and_imports');

const getTemplate = (source, imports) => {
const requires = imports.map(i => `require('${i}');`).join('\n');

return `var stache = require('can/dist/cjs/view/stache/stache');
var mustacheCore = require('can/dist/cjs/view/stache/mustache_core');
var getIntermediateAndImports = require('can/dist/cjs/view/stache/intermediate_and_imports');
return `var stache = require('can-stache');
var mustacheCore = require('can-stache/src/mustache_core');
var getIntermediateAndImports = require('can-stache/src/intermediate_and_imports');
${requires}
Expand All @@ -27,11 +24,10 @@ module.exports = function (scope, options, nodeList) {
return renderer(scope, options.add(moduleOptions), nodeList);
};`;
}
};

module.exports = function canStacheLoader(source) {
const src = JSON.stringify(source);

const intermediateAndImports = getIntermediateAndImports(source);

return getTemplate(src, intermediateAndImports.imports);
Expand Down
62 changes: 0 additions & 62 deletions intermediate_and_imports.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "can-stache-loader",
"version": "0.2.1",
"version": "1.0.0-beta",
"description": "CanJS Stache loader for WebPack",
"main": "index.js",
"scripts": {
Expand All @@ -20,7 +20,6 @@
"mustache"
],
"dependencies": {
"can": "^2.3.31",
"can-stache": "^3.0.25",
"can-view-parser": "^3.3.0"
},
Expand Down

0 comments on commit e61b351

Please sign in to comment.