-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Use storybook for electron app #1435
Comments
the problem is the iframe that displays the content doesn't inherit |
some insight on how to deal with this? |
Has anyone been able to get this working with Electron? Would love to use Storybook for our Electron based project. |
Just a thought. If Storybook – when used in Electron – could use the special webview tags (with node integration) instead of iframes, I think it would work. |
OK, got it working! 😜 Here is my module.exports = {
target: 'electron-renderer',
externals: {
'fs': 'top.require(\'fs\')',
'path': 'top.require(\'path\')',
'events': 'top.require(\'events\')',
'electron': 'top.require(\'electron\')',
'util': 'top.require(\'util\')',
'querystring': 'top.require(\'querystring\')',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
presets: ['@babel/react', '@babel/flow',
['@babel/preset-env', {
'targets': {
'electron': '3.0.4'
}
}]
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
['@babel/plugin-transform-modules-commonjs', {
'lazy': (module) => {
// console.log(module)
return true
}
}]
],
}
},
{
test: /(\.less|\.css)$/,
use: ['style-loader', 'css-loader', 'less-loader'],
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }]
},
} |
Hi, I may have solution to this issue. As @dperetti mentioned, it would be useful to have stories that running inside webview tag. |
Attempting to get Storybook working with electron v7.1.7 & electron-renderer components as per your comment. Am currently running:
Any ideas would be much appreciated! Cheers :) |
Try to add this before the plugins: [
new webpack.DefinePlugin({
// Workaround for has-symbol failing to find global in iframe.
global: '(typeof(global) == "undefined" ? top.global : global)',
process: '(typeof(process) == "undefined" ? top.process : process)',
'window.require': 'top.window.require',
}),
], |
Also, as for the externals, there is a new |
Thanks for your help! I gave it a try, but ended up with Regardless, I think my knowledge of webpack / storybook is not currently sufficient to fix this issue, so I'll leave this for now and return when i've done enough study to properly troubleshoot rather than bandaid. Also had a brief look at |
Are you sure the plugins are applied? My const options = {
target: 'electron-renderer', // https://github.com/webpack/webpack/pull/1467
externals: {
'fs': 'top.require(\'fs\')',
'os': 'top.require(\'os\')',
'stream': 'top.require(\'stream\')',
'assert': 'top.require(\'assert\')',
'constants': 'top.require(\'constants\')',
'process': 'top.require(\'process\')',
'crypto': 'top.require(\'crypto\')',
'path': 'top.require(\'path\')',
'events': 'top.require(\'events\')',
'electron': 'top.require(\'electron\')',
'util': 'top.require(\'util\')',
'querystring': 'top.require(\'querystring\')',
'worker_threads': {}, // shut up annoying warning triggered by node_modules/write-file-atomic/index.js
},
resolve: { // http://webpack.github.io/docs/configuration.html#resolve
alias: {
},
extensions: ['.mjs', ".ts", ".tsx", ".js"]
},
plugins: [
new webpack.DefinePlugin({
// Workaround for has-symbol failing to find global in iframe.
global: '(typeof(global) == "undefined" ? top.global : global)',
process: '(typeof(process) == "undefined" ? top.process : process)',
'window.require': 'top.window.require',
}),
],
module: {
rules: [...]
},
}
module.exports = async ({ config, mode }) => {
// console.log(config)
const c = {
...config,
plugins: [...config.plugins, ...options.plugins],
externals: options.externals,
resolve: options.resolve,
module: { ...config.module, ...options.module }
}
return c
} Also I launch Storybook like this:
And I launch electron separately:
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer')
const app = require('electron').app
const BrowserWindow = require('electron').BrowserWindow
app.commandLine.appendSwitch('disable-web-security')
app.commandLine.appendSwitch('remote-debugging-port', '5858')
app.on('ready', function() {
mainWindow = new BrowserWindow({
width: 1100,
height: 800,
allowRunningInsecureContent: true,
webPreferences: {
nodeIntegration: true,
webviewTag: false,
sandbox: false,
allowRunningInsecureContent: true,
offscreen: false,
webSecurity: false,
contextIsolation: false,
},
})
mainWindow.loadURL('http://localhost:9001')
installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}) So it's totally possible to tweak the |
After completely copying the The only thing I needed to change was adding |
We do not support electron, and don't have any plans to add support right now. |
versions:
I'm trying to use Storybook with an electron app. The components are vanilla JS, but some of them import modules from
electron
In my app, I configure webpack to
target: 'electron-renderer'
, and this works fineHowever, in
storybook
, doing so results in the error below.Has anyone configured storybook to work correctly with electron?
The text was updated successfully, but these errors were encountered: