Skip to content

Commit

Permalink
Fix craco.config.js to use emotion plugin and fix the CSP for <img>, …
Browse files Browse the repository at this point in the history
…<video>, and <audio> to work
  • Loading branch information
whitphx committed Sep 28, 2022
1 parent 4e26771 commit 2f45604
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/desktop/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin")

module.exports = {
babel: {
plugins: ["@emotion"],
loaderOptions: {
cacheDirectory: true,
},
},
webpack: {
configure: (webpackConfig, { env: webpackEnv, paths}) => {
const isEnvDevelopment = webpackEnv === 'development';
Expand All @@ -19,7 +25,11 @@ module.exports = {
'worker-src blob:',
"script-src-elem 'self' blob: https://cdn.jsdelivr.net/",
// Allow loading the hosted wheels
'connect-src https://cdn.jsdelivr.net/ https://pypi.org/ https://files.pythonhosted.org/' + (isEnvDevelopment ? ' http://localhost:3000/ ws://localhost:3000/' : '')
'connect-src https://cdn.jsdelivr.net/ https://pypi.org/ https://files.pythonhosted.org/' + (isEnvDevelopment ? ' http://localhost:3000/ ws://localhost:3000/' : ''),
// Allow <img> to load any resources
'img-src * blob:',
// Allow <audio> and <video> to load any resources
'media-src * blob:',
].join("; ")
htmlWebpackPlugin.options.meta['Content-Security-Policy'] = { 'http-equiv': 'Content-Security-Policy', 'content': csp }

Expand Down
14 changes: 13 additions & 1 deletion packages/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ function App() {
data: `import streamlit as st
name = st.text_input("name")
st.write("Hello,", name or "Electron!")`,
st.write("Hello,", name or "Electron!")
import matplotlib.pyplot as plt
import numpy as np
arr = np.random.normal(1, 1, size=100)
fig, ax = plt.subplots()
ax.hist(arr, bins=20)
st.pyplot(fig)
st.image("https://raw.githubusercontent.com/whitphx/stlite/main/docs/images/logo.svg")
`,
},
[snapshotMountFilePath]: {
data: snapshotFileBin,
Expand Down

0 comments on commit 2f45604

Please sign in to comment.