Skip to content

Commit

Permalink
remove webpack and begin replace with vite
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Jan 18, 2024
1 parent 313adfc commit 7d457d7
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 4,869 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ reactR.Rcheck
reactR_*.tar.gz
*.swp
.DS_Store
inst/www/react-tools/react*.js
4 changes: 2 additions & 2 deletions R/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ html_dependency_reacttools <- function(){
htmltools::htmlDependency(
name = "reactwidget",
src = "www/react-tools",
version = "1.0.0",
version = "2.0.0",
package = "reactR",
script = c("react-tools.js")
script = c("react-tools.umd.js")
)
}

Expand Down
1 change: 0 additions & 1 deletion inst/www/react-tools/react-tools.js.map

This file was deleted.

1 change: 1 addition & 0 deletions inst/www/react-tools/react-tools.umd.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(require("react"),require("react-dom"),require("shiny"),require("jquery")):typeof define=="function"&&define.amd?define(["react","react-dom","shiny","jquery"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.React,s.ReactDOM,s.Shiny,s.$))})(this,function(s,c,l,u){"use strict";function o(n,t){if(typeof t=="string")return t;if(t.name[0]===t.name[0].toUpperCase()&&!n.hasOwnProperty(t.name))throw new Error("Unknown component: "+t.name);for(var i=n.hasOwnProperty(t.name)?n[t.name]:t.name,r=[i,t.attribs],e=0;e<t.children.length;e++)r.push(o(n,t.children[e]));return React.createElement.apply(React,r)}const p={widthProperty:"width",heightProperty:"height",appendPx:!1,renderOnResize:!1};function w(n){var t={};for(var i in p)t[i]=p[i];for(var i in n){if(!p.hasOwnProperty(i))throw new Error("Unrecognized option: "+i);t[i]=n[i]}return t}function h(n,t){return t.appendPx?n+"px":n}function b(n,t,i,r){var e=w(r);window.HTMLWidgets.widget({name:n,type:t,factory:function(a,d,y){var g,P={},m=function(f){e.renderOnResize&&(typeof f.tag=="object"&&(f.tag.attribs[e.widthProperty]=h(d),f.tag.attribs[e.heightProperty]=h(y)),g=f),this.instance.component=ReactDOM.render(o(i,f.tag),a)};return{instance:P,renderValue:m,resize:function(f,v){e.renderOnResize&&(d=f,y=v,m(g))}}}})}function O(n,{configuration:t,value:i}){let r=!1;t!==void 0&&(this.setInputConfiguration(n,t),r=!0),i!==void 0&&(this.setInputValue(n,i),r=!0),r&&(this.getCallback(n)(),this.render(n))}const V={receiveMessage:O,type:!1,ratePolicy:null};function I(n,t,i,r){r=Object.assign({},V,r),l.inputBindings.register(new class extends l.InputBinding{find(e){return u(e).find(n)}getValue(e){return this.getInputValue(e)}setValue(e,a,d=!1){u(e).data("callback")!==void 0&&(this.setInputValue(e,a),this.getCallback(e)(d),this.render(e))}initialize(e){u(e).data("value",JSON.parse(u(e).next().text())),u(e).data("configuration",JSON.parse(u(e).next().next().text()))}subscribe(e,a){u(e).data("callback",a),this.render(e)}unsubscribe(e){c.render(null,e)}receiveMessage(e,a){r.receiveMessage.call(this,e,a)}getType(e){if(typeof r.type=="function")return r.type.call(this,e);if(r.type===!1||typeof r.type=="string")return r.type;throw new Error("options.type must be false, a string, or a function")}getRatePolicy(){return r.ratePolicy}getInputValue(e){return u(e).data("value")}setInputValue(e,a){u(e).data("value",a)}getInputConfiguration(e){return u(e).data("configuration")}setInputConfiguration(e,a){u(e).data("configuration",a)}getCallback(e){return u(e).data("callback")}render(e){const a=s.createElement(i,{configuration:this.getInputConfiguration(e),value:this.getValue(e),setValue:this.setValue.bind(this,e),el:e});c.render(a,e)}},t)}window.reactR={reactShinyInput:I,reactWidget:b,hydrate:o}});
30 changes: 8 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
{
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@rgrove/parse-xml": "^1.1.1",
"babel-loader": "^8.0.5",
"chai": "^4.2.0",
"karma": "^3.1.4",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-source-map-support": "^1.3.0",
"karma-webpack": "^4.0.0-rc.6",
"mocha": "^5.2.0",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-html-parser": "^2.0.2",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2"
},
"name": "react-tools",
"private": true,
"type": "module",
"scripts": {
"test": "karma start --single-run --browsers ChromeHeadless karma.conf.js"
"build": "vite build"
},
"devDependencies": {
"vite": "^5.0.11"
},
"dependencies": {}
}
}
27 changes: 27 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { resolve, join } from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
define: { 'process.env.NODE_ENV': '"production"' },
build: {
outDir: join(__dirname, "inst/www/react-tools/"),
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, '/srcjs/react-tools.js'),
name: 'reactR',
// the proper extensions will be added
fileName: 'react-tools',
},
rollupOptions: {
external: ['react', 'react-dom', 'jquery', 'shiny'],
output: {
globals: {
'react': 'React',
'react-dom': 'ReactDOM',
'jquery': '$',
'shiny': 'Shiny'
},
},
},
},
});
Loading

0 comments on commit 7d457d7

Please sign in to comment.