Skip to content

Commit

Permalink
feat: rm /lib and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vagusX committed Mar 27, 2017
1 parent 3355506 commit 8709fad
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
13 changes: 3 additions & 10 deletions lib/index.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ module.exports = function (content) {

meta.url = result[1] + '.html'

var _this = this
var callback = this.async()
var _this = this

bundler(url, function(inlinedHtml) {
_this.emitFile(result[1] + '.html', inlinedHtml)
callback(null, 'module.exports = ' + (JSON.stringify(meta)))
})
} else {
return 'module.exports = ' + (JSON.stringify(meta))
throw new Error('This html module dont have any module id')
}
}

Expand All @@ -44,14 +44,7 @@ function bundler (target, callback) {
inlineCss: true,
stripComments: true
}).process(target, function (err, inlinedHtml) {
onError(err)
if (err) throw err
callback(inlinedHtml)
})
}

function onError (err) {
if (err) {
console.error(err + '\n' + err.stack)
throw err
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "html-imports-loader",
"description": "",
"main": "lib/index.js",
"main": "index.js",
"scripts": {
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand Down
48 changes: 47 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@ $ npm install html-imports-loader
```

## Usage
wait for a minute

Webpack config when dev
```js
{
test: /\.html$/,
use: [
{
loader: 'html-imports-loader'
}
],
include: /bower_components/,
exclude: /public/
}
```

*And pls serve the bower_components folder in your static server at the same time for better dev exprience.*

Here's a sample in `express`

```js
// serve bower components
app.use('/bower_components', express.static('./bower_components'))

```

Webpack config when production
```js
{
test: /\.html$/,
use: [
{
loader: 'html-imports-loader',
options: {
emitFile: true
}
}
],
include: /bower_components/,
exclude: /public/
}
```

With the config `emitFile` you can get a vulcanized html modules.

## Todos
* User config for vulcanize
* Emit as a React/Vue/Ng Component

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

0 comments on commit 8709fad

Please sign in to comment.