Skip to content

Commit

Permalink
Merge pull request #26 from swup/next
Browse files Browse the repository at this point in the history
Update for swup 4
  • Loading branch information
hirasso committed Jul 26, 2023
2 parents 37a8d78 + 0f713b3 commit c81b477
Show file tree
Hide file tree
Showing 16 changed files with 5,715 additions and 6,929 deletions.
22 changes: 0 additions & 22 deletions .github/ISSUE_TEMPLATE/issue-template.md

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
registry-url: https://registry.npmjs.org/
node-version: 16
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm publish --access public
env:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/version-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow bumps the package.json version and creates a PR

name: Update package version

on:
workflow_dispatch:
inputs:
segment:
description: 'Semver segment to update'
required: true
default: 'patch'
type: choice
options:
- minor
- patch

jobs:
update-version:
name: Update package version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: echo "Updating ${{ inputs.segment }} version"
- name: Update version
run: npm --no-git-tag-version version ${{ inputs.segment }}
- uses: peter-evans/create-pull-request@v4
with:
base: 'master'
branch: 'version/automated'
title: 'Update package version (automated)'
commit-message: 'Update package version'
body: 'Automated update to ${{ inputs.segment }} version'
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ wiki-wishlist
*.sublime-workspace
.editorconfig
.idea
lib
/plugins
/dist
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
16 changes: 0 additions & 16 deletions .npmignore

This file was deleted.

23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

<!-- ## [Unreleased] -->

## [2.0.0] - 2023-07-26

- Switch to microbundle
- Export native ESM module
- Update for swup 4 compatibility

## [1.1.0] - 2020-03-01

- Allow opting into reloading script

## [1.0.0] - 2019-05-26

- Initial release

[Unreleased]: https://github.com/swup/scripts-plugin/compare/2.0.0...HEAD

[2.0.0]: https://github.com/swup/scripts-plugin/releases/tag/2.0.0
[1.1.0]: https://github.com/swup/scripts-plugin/releases/tag/1.1.0
[1.0.0]: https://github.com/swup/scripts-plugin/releases/tag/1.0.0
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Swup Scripts Plugin

A [swup](https://swup.js.org) plugin for re-evaluating scripts.

Re-run any `<script>` tags inside the `<head>` and/or `<body>` on every page view. This can be
helpful if you don't have full control over the scripts included on your website.

Ignores any script tags with the attribute `[data-swup-ignore-script]`. This attribute **must be**
on the script tag that initializes swup itself to prevent creating multiple swup instances.

**🚨 Warning:** Use this plugin as a last resort for projects with limited control over the included
scripts. Running scripts without destroying previous ones can cause memory leaks and potentially
break your page.

## Installation

Install the plugin from npm and import it into your bundle.

```bash
npm install @swup/scripts-plugin
```

```javascript
import SwupScriptsPlugin from '@swup/scripts-plugin';
```

Or include the minified production file from a CDN:

```html
<script src="https://unpkg.com/@swup/scripts-plugin@2"></script>
```

## Usage

To run this plugin, include an instance in the swup options.

```javascript
const swup = new Swup({
plugins: [new SwupScriptsPlugin()]
});
```

## Options

### head / body

The plugin provides two boolean options — `head` and `body`. Both are set to `true` by default.
Set these to `false` to disable re-evaluating scripts globally in the head or body of your website.

```javascript
new SwupScriptsPlugin({
head: true,
body: true
});
```

### optin

Some third-party libraries like Google Tag Manager might not give you any control over how
scripts are inserted into the page. In that case, enabling the `optin` option will only reload the
scripts explicitly marked with a `[data-swup-reload-script]` attribute.

```javascript
new SwupScriptsPlugin({
optin: false
});
```
Loading

0 comments on commit c81b477

Please sign in to comment.