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

How to add a <script> tag? #163

Closed
moroshko opened this issue May 4, 2016 · 7 comments
Closed

How to add a <script> tag? #163

moroshko opened this issue May 4, 2016 · 7 comments

Comments

@moroshko
Copy link

moroshko commented May 4, 2016

react-prism recommends to add a script tag directly in the HTML:

<script src="path/to/your/prism.js" ></script>

Is there a way to do this?

@jeef3
Copy link
Contributor

jeef3 commented May 4, 2016

Yes, there is, but I don't think there's any docs on it yet. See #77.

Basically, create a head.html in your .storybook. That will get included.

Note: This will add it to <head>

@moroshko
Copy link
Author

moroshko commented May 4, 2016

Thanks!

@helloncanella
Copy link

updating the answer: add a preview-head.html to the folder .storybook.

@ericclemmons
Copy link
Contributor

There doesn't seem to be a way to do this for local dependencies. What's the best way to get these into stories & the build output?

<script nomodule src="/dist/my-custom-script.js"></script>

Error: ENOENT: no such file or directory, stat '.../my-project/node_modules/@storybook/core/dist/public/dist/my-custom-script.js'

@rdhainaut
Copy link

You can find the doc on the official website at this address: https://storybook.js.org/docs/configurations/add-custom-head-tags/

@onderceylan
Copy link

Local dependencies can be copied over to the dist via the webpack copy plugin. This is how I loaded my local dependency;

main.js

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  stories: ['../src/**/*.stories.ts'],
  webpackFinal: config => {
    config.plugins.push(
      new CopyPlugin({
        patterns: [{ from: './node_modules/@myorg/my-local-dep/dist', to: './my-local-dep-dist/' }],
      })
    );
    return config;
  },
};

preview-head.html

<script async type="module" src="/my-local-dep-dist/my-script.esm.js"></script>

@James-Wilkinson-git
Copy link

Looking for a way to do this per story, not for all stories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants