Skip to content
Permalink
Browse files

fix: move basePath to an option

  • Loading branch information
assisrafael committed Feb 22, 2017
1 parent 0acda2b commit ac1e23a689715f4c26ea319df264d64fbcc304ab
Showing with 28 additions and 3 deletions.
  1. +15 −0 README.md
  2. +8 −2 src/index.js
  3. +5 −1 test/index.js
@@ -3,3 +3,18 @@
[![NPM](https://nodei.co/npm/babel-plugin-angular-inline-template.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/babel-plugin-angular-inline-template/)

Babel plugin for inlining templates into angular 1.X components and directives


## How to use

In `.babelrc` or similar:

```json
{
plugins: [
['babel-plugin-angular-inline-template, {
basePath: '<ROOT-PATH-TO-YOUR-FILE>'
}]
]
}
```
@@ -28,8 +28,14 @@ function replaceTemplateUrlWithTemplate(node, basePath) {
module.exports = function() {
return {
visitor: {
ObjectProperty(nodePath, file) {
replaceTemplateUrlWithTemplate(nodePath.node, 'test/fixtures');
ObjectProperty(nodePath, state) {
const basePath = state.opts.basePath;

if (!basePath) {
throw new Error('babel-plugin-angular-inline-template requires a base path to run');
}

replaceTemplateUrlWithTemplate(nodePath.node, basePath);
}
}
};
@@ -28,7 +28,11 @@ function runTests() {
function runTest(dir) {
var exitCode = 0;
var output = babel.transformFileSync(dir.path + '/actual.js', {
plugins: [pluginPath]
plugins: [
[pluginPath, {
basePath: 'test/fixtures'
}]
]
});

var expected = fs.readFileSync(dir.path + '/expected.js', 'utf-8');

0 comments on commit ac1e23a

Please sign in to comment.
You can’t perform that action at this time.