rollup-plugin-script-tag

1.0.1 • Public • Published

rollup-plugin-script-tag

A rollup plugin that will bundle javascript from within <script> tags. Treat files that contain <script></script> tags as modules by importing them into your bundle.

Installation

npm install --save-dev rollup-plugin-script-tag

Usage

// rollup.config.js
 
import scriptTag from 'rollup-plugin-script-tag'
 
export default {
  input: 'bundle.js'
  plugins: [
    scriptTag() // Load first, before any other plugins
  ]
}
// bundle.js
 
import foo from './example.html'
 
export default foo()
<!-- example.html -->
 
<script>
  export default function foo() {
    return console.log('hello world')
  }
</script> 

Options

There a 2 options that can be applied

scriptTag({
  extensions: [],
  exclude: []
})

Extensions

The extensions accepts an array. The extensions option will allow you to parse and accept different file extensions that contain <script> tags. There are several common extensions that are included by default, they are:

  • .erb
  • .handlebars
  • .hbs
  • .htm
  • .html
  • .liquid
  • .mustache
  • .nunjucks
  • .php
  • .tag
  • .twig
  • .we

Please Note:

Defining new extensions will overwrite all defaults, create a PR if you would like default extensions to be included.

Exclude

The exclude options accepts an array. The exclude options allows you to skip parsing imports. This is helpful if you're using another rollup plugin like rollup-plugin-html.

scriptTag({
  exclude: [
    'index.html' // index.html import will be excluded
  ]
})

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Contributions and feedback are very welcome.

To get it running:

  1. Clone the project.
  2. npm install
  3. npm run build

License

The MIT License (MIT). Please see License File for more information.

Package Sidebar

Install

npm i rollup-plugin-script-tag

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

7.18 kB

Total Files

6

Last publish

Collaborators

  • sissel