simonw / datasette-edit-schema

Datasette plugin for modifying table schemas
Apache License 2.0
16 stars 0 forks source link

Vendor draggable into static/ folder #16

Closed simonw closed 3 years ago

simonw commented 3 years ago

I should vendor this into the plugin's /static/ folder. _Originally posted by @simonw in https://github.com/simonw/datasette-edit-tables/pull/14#discussion_r496300827_

simonw commented 3 years ago

Slight concern: what happens if another plugin also needs the Draggable library?

I'm going to ignore that for the moment. If it DOES happen stuff will probably continue to work anyway, since Draggable is a pretty stable library and loading it twice will simply result in the second-loaded version over-riding the Draggable symbol that was created by the first-loaded version.

simonw commented 3 years ago

I downloaded it like so:

cd datasette_edit_tables/static
wget 'https://cdn.jsdelivr.net/npm/@shopify/draggable@1.0.0-beta.11/lib/draggable.bundle.js'
mv draggable.bundle.js draggable.1.0.0-beta.11.bundle.js

I added this to the top of the file:

/*
MIT License. Copyright (c) 2018 Shopify
https://github.com/Shopify/draggable
*/

I tried applying this recipe: https://til.simonwillison.net/til/til/javascript_minifying-uglify-npx.md

npx uglify-js draggable.1.0.0-beta.11.bundle.js -o draggable.1.0.0-beta.11.bundle.min.js --comments '/License/'
npx: installed 1 in 1.156s
Parse error at draggable.1.0.0-beta.11.bundle.js:615,0
const onSortableSorted = Symbol('onSortableSorted');
^
ERROR: Unexpected token: keyword «const»

Turns out uglify-js doesn't support ES6. So I used tercer instead:

npx terser draggable.1.0.0-beta.11.bundle.js -o draggable.1.0.0-beta.11.bundle.min.js --comments '/License/'
npx: installed 6 in 1.743s

This dropped it from 198K to 117K which is good enough for the moment.

% ls -lah
-rw-r--r--@ 1 simon  staff   198K Sep 30 17:49 draggable.1.0.0-beta.11.bundle.js
-rw-r--r--@ 1 simon  staff   117K Sep 30 17:53 draggable.1.0.0-beta.11.bundle.min.js