Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Rollup for production builds #165

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/prettier-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup Node
uses: actions/setup-node@v1
- name: Setup node
uses: actions/setup-node@v2
with:
version: '12.x'
node-version: '12'
cache: 'yarn'
- run: yarn
working-directory: javascript/
- run: yarn lint
Expand Down
32 changes: 20 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,31 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [2.6.6, 2.7.2, '3.0']
ruby-version: [2.6, 2.7, 3.0]
steps:
- uses: actions/checkout@master
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Bundle install
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
bundler-cache: true
- name: Run ruby tests
run: bundle exec rake test

javascript_build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '12', '14', '16' ]
name: Node v${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
- name: Build javascript package
run: |
yarn install
yarn build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules/
.byebug_history
*.log
/.dir-locals.el
/dist
15 changes: 1 addition & 14 deletions javascript/cable_ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { xpathToElement, dispatch } from './utils'
import activeElement from './active_element'
import OperationStore from './operation_store'
import actionCable from './action_cable'
import StreamFromElement from './elements/stream_from_element'
import UpdatesForElement from './elements/updates_for_element'

const perform = (
operations,
Expand Down Expand Up @@ -72,17 +70,6 @@ const performAsync = (
})
}

const initialize = (initializeOptions = {}) => {
const { consumer } = initializeOptions
actionCable.setConsumer(consumer)

if (!customElements.get('stream-from'))
customElements.define('stream-from', StreamFromElement)

if (!customElements.get('updates-for'))
customElements.define('updates-for', UpdatesForElement)
}

export { perform, performAsync, initialize }
export { perform, performAsync }

export const consumer = actionCable.getConsumer()
9 changes: 6 additions & 3 deletions javascript/elements/stream_from_element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import CableReady from '..'
import {
consumer as CableReadyConsumer,
perform as CableReadyPerform
} from '../cable_ready'
import SubscribingElement from './subscribing_element'

export default class StreamFromElement extends SubscribingElement {
async connectedCallback () {
if (this.preview) return
const consumer = await CableReady.consumer
const consumer = await CableReadyConsumer
if (consumer) {
this.createSubscription(
consumer,
Expand All @@ -19,6 +22,6 @@ export default class StreamFromElement extends SubscribingElement {
}

performOperations (data) {
if (data.cableReady) CableReady.perform(data.operations)
if (data.cableReady) CableReadyPerform(data.operations)
}
}
2 changes: 0 additions & 2 deletions javascript/elements/subscribing_element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import CableReady from '..'

export default class SubscribingElement extends HTMLElement {
disconnectedCallback () {
if (this.channel) this.channel.unsubscribe()
Expand Down
4 changes: 2 additions & 2 deletions javascript/elements/updates_for_element.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import morphdom from 'morphdom'

import CableReady from '..'
import { consumer as CableReadyConsumer } from '../cable_ready'
import SubscribingElement from './subscribing_element'
import { shouldMorph } from '../morph_callbacks'
import activeElement from '../active_element'
Expand Down Expand Up @@ -30,7 +30,7 @@ export default class UpdatesForElement extends SubscribingElement {
if (this.preview) return
this.update = debounce(this.update.bind(this), this.debounce)

const consumer = await CableReady.consumer
const consumer = await CableReadyConsumer
if (consumer) {
this.createSubscription(consumer, 'CableReady::Stream', this.update)
} else {
Expand Down
14 changes: 13 additions & 1 deletion javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ import * as MorphCallbacks from './morph_callbacks'
import { shouldMorphCallbacks, didMorphCallbacks } from './morph_callbacks'
import * as Utils from './utils'
import OperationStore, { addOperation, addOperations } from './operation_store'
import { perform, performAsync, initialize, consumer } from './cable_ready'
import { perform, performAsync, consumer } from './cable_ready'
import StreamFromElement from './elements/stream_from_element'
import UpdatesForElement from './elements/updates_for_element'
import SubscribingElement from './elements/subscribing_element'
import actionCable from './action_cable'

const initialize = (initializeOptions = {}) => {
const { consumer } = initializeOptions
actionCable.setConsumer(consumer)

if (!customElements.get('stream-from'))
customElements.define('stream-from', StreamFromElement)

if (!customElements.get('updates-for'))
customElements.define('updates-for', UpdatesForElement)
}

export {
Utils,
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@
},
"license": "MIT",
"author": "Nathan Hopkins <[email protected]>",
"main": "./javascript/index.js",
"module": "./javascript/index.js",
"main": "./dist/cable_ready.umd.js",
"module": "./dist/cable_ready.module.js",
"files": [
"dist/*",
"src/*"
marcoroth marked this conversation as resolved.
Show resolved Hide resolved
],
"scripts": {
"lint": "yarn run prettier-standard:check",
"format": "yarn run prettier-standard:format",
"prettier-standard:check": "yarn run prettier-standard --check ./javascript/**/*.js",
"prettier-standard:format": "yarn run prettier-standard ./javascript/**/*.js"
"prettier-standard:format": "yarn run prettier-standard ./javascript/**/*.js",
"build": "yarn rollup -c",
"watch": "yarn rollup -wc"
},
"dependencies": {
"morphdom": "^2.6.1"
},
"devDependencies": {
"prettier-standard": "^16.4.1"
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"prettier-standard": "^16.4.1",
"rollup": "^2.60.0"
}
}
33 changes: 33 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import resolve from "@rollup/plugin-node-resolve"
import commonjs from '@rollup/plugin-commonjs';

const basePlugins = [
resolve(),
commonjs()
]

export default [
{
external: ["morphdom"],
input: "javascript/index.js",
output: [
{
name: "CableReady",
file: "dist/cable_ready.umd.js",
format: "umd",
sourcemap: true,
exports: "named",
globals: {morphdom: "morphdom"}, // UMD build wants a global...annoying.
},
{
file: "dist/cable_ready.module.js",
format: "es",
sourcemap: true,
}
],
plugins: basePlugins,
watch: {
include: "javascript/**"
}
},
]
Loading