rollup-plugin-script-tag
v1.0.1
Published
Rollup plugin for bundling javascript within <script> tags.
Downloads
3
Readme
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:
- Clone the project.
npm install
npm run build
License
The MIT License (MIT). Please see License File for more information.