Documentation Tutorials

Injections

import {
  inject
} from 'js-web'

Injections allow you to bundle your script and style files to include them on your site.

The recommended way to use injections is to create an injection array.

const injections = [
    inject.jquery(),
    inject.bootstrap(),
    inject.style('style/site.css'),
    inject.script('script/main.js')
  ]

Then, you can add the injections array to the htmlRoutes as the last parameter.

htmlRoute('/','html/index.html', async (input,session,cookie) => {
  return {}
},injections)

Inject

Build in libraries

const injections = [
    inject.jquery(),
    inject.bootstrap(),
    inject.socketIO()
  ]

Inject.script()

The inject script can take a file or url.

const injections = [
    inject.script('script/site.js'),
    inject.script('http://cdn.somelib.com/file.js')
  ]

Inject.style()

The inject style can take css- , sass- and stylus files.

const injections = [
    inject.style('site.sass'),
    inject.script('site.styl'),
    inject.script('site.css')
  ]

Google Analytics

const injections = [
    inject.googleAnalytics()
  ]

React

It's possible to inject react into your project.

Add a react inject to the injections array.

const injections = [
    inject.react('react/app.jsx','app-id')
  ]

Create react root/app component

export default class App extends React.Component{
  render(){
    return (
      <h1> Hey i am react!</h1>
    )
  }
}

Add a binding div to the html file.

<div id="app-id">

</div>