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

Docs: IE11 example #1327

Closed
wants to merge 1 commit into from

Conversation

smashercosmo
Copy link
Collaborator

Here is minimal example of react-styleguidist that works in IE11

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! FAQ could be a better place for that.

Please add explanation why it works.

@smashercosmo
Copy link
Collaborator Author

@sapegin do you want me to add FAQ section in addition to example or instead?

@sapegin
Copy link
Member

sapegin commented Apr 9, 2019 via email

@abhishekdev
Copy link
Contributor

abhishekdev commented Apr 16, 2019

I was not able to get the generated site to render in IE11 with v9.0.7. IE 11 throws Syntax Error on acorn-jsx code. To be precise, IE11 fails on the class keyword on this line from acorn-jsx. There might be other errors as well, but it bails out on the first.

I ran a build on @smashercosmo's branch by running

node lib/bin/styleguidist.js server --config examples/ie11/styleguide.config.js

This build throws the following compiler warnings and It does not seem the site is served( irrespective of browser). Am I missing something? cause it seems the warning and the IE11 issue may be related and maybe the target files from acorn-jsx & regexpu-core may not have been processed at all.

 WARN  Compiled with warnings

./node_modules/buble/dist/buble-browser.es.js
Attempted import error: 'acorn-jsx' does not contain a default export (imported as 'acornJsx').
 @ ./lib/client/utils/compileCode.js
 @ ./lib/client/rsg-components/ReactExample/ReactExample.js
 @ ./lib/client/rsg-components/ReactExample/index.js
 @ ./lib/client/rsg-components/Preview/Preview.js
 @ ./lib/client/rsg-components/Preview/index.js
 @ ./lib/client/rsg-components/Playground/Playground.js
 @ ./lib/client/rsg-components/Playground/index.js
 @ ./lib/client/rsg-components/Examples/Examples.js
 @ ./lib/client/rsg-components/Examples/index.js
 @ ./lib/client/rsg-components/Section/Section.js
 @ ./lib/client/rsg-components/Section/index.js
 @ ./lib/client/rsg-components/Sections/Sections.js
 @ ./lib/client/rsg-components/Sections/index.js
 @ ./lib/client/rsg-components/StyleGuide/StyleGuide.js
 @ ./lib/client/rsg-components/StyleGuide/index.js
 @ ./lib/client/utils/renderStyleguide.js
 @ ./lib/client/index.js
 @ multi core-js ./lib/client/index ./node_modules/react-dev-utils/webpackHotDevClient.js
./node_modules/buble/dist/buble-browser.es.js
Attempted import error: 'regexpu-core' does not contain a default export (imported as 'rewritePattern').
 @ ./lib/client/utils/compileCode.js
 @ ./lib/client/rsg-components/ReactExample/ReactExample.js
 @ ./lib/client/rsg-components/ReactExample/index.js
 @ ./lib/client/rsg-components/Preview/Preview.js
 @ ./lib/client/rsg-components/Preview/index.js
 @ ./lib/client/rsg-components/Playground/Playground.js
 @ ./lib/client/rsg-components/Playground/index.js
 @ ./lib/client/rsg-components/Examples/Examples.js
 @ ./lib/client/rsg-components/Examples/index.js
 @ ./lib/client/rsg-components/Section/Section.js
 @ ./lib/client/rsg-components/Section/index.js
 @ ./lib/client/rsg-components/Sections/Sections.js
 @ ./lib/client/rsg-components/Sections/index.js
 @ ./lib/client/rsg-components/StyleGuide/StyleGuide.js
 @ ./lib/client/rsg-components/StyleGuide/index.js
 @ ./lib/client/utils/renderStyleguide.js
 @ ./lib/client/index.js
 @ multi core-js ./lib/client/index ./node_modules/react-dev-utils/webpackHotDevClient.js

abhishekdev added a commit to abhishekdev/react-styleguidist that referenced this pull request Apr 17, 2019
- Prepend a specific loader to support IE11 to `webpack.config.module.rules`
- Set the babel config option in the loader rules to avoid conflicting changes with complex babel-config files. This also works with `.babelrc.js`
- This handles cases for webpack nested rules. Ref: https://webpack.js.org/configuration/module/#nested-rules

[Ref styleguidist#1327]
abhishekdev added a commit to abhishekdev/react-styleguidist that referenced this pull request Apr 17, 2019
@abhishekdev
Copy link
Contributor

abhishekdev commented Apr 17, 2019

I could make the example by @smashercosmo work! The initial issue I came across turned out to be related to npm and how it dedupes packages.

A few other scenarios I came across while trying to make it work for my project:

  • Using custom presets in babel config. This can impact the workability of the example. e.g. Babel 7 requires a file named babel.config.js (vs. .babelrc.js) to process dependencies.
  • Ability to work with nested webpack rules

FWIW: Based on @smashercosmo findings, here is the config that worked for me

const TRANSFORMS_FOR_IE11 = {
  test: /\.jsx?$/,
  include: new RegExp(
        `node_modules/(?=(${[
          // ref: https://github.com/styleguidist/react-styleguidist/pull/1327
          'acorn-jsx',
          'estree-walker',
          'regexpu-core',
          'unicode-match-property-ecmascript',
          'unicode-match-property-value-ecmascript',
          'react-dev-utils',
          'ansi-styles',
          'ansi-regex',
          'chalk',
          'strip-ansi'
      ].join('|')})/).*`
  ),
  use: {
    loader: "babel-loader",
    options: {
      presets: [
        [
          "@babel/preset-env",
          {
            targets: {
              ie: "11"
            }
          }
        ]
      ]
    }
  }
};
webpackConfig.module.rules = [
  TRANSFORMS_FOR_IE11,
  ...webpackConfig.module.rules
];

@nlt2390
Copy link

nlt2390 commented Jun 18, 2019

@abhishekdev Using [email protected], got IE error and ur code works for me.

@stonebk
Copy link

stonebk commented Jul 31, 2019

I also had to add estree-walker to the includes to get this to work for me in [email protected]

@kopax
Copy link
Collaborator

kopax commented Oct 10, 2019

Could this be included by default in the configuration so everyone use a styleguidist compatible with IE11?

@smashercosmo
Copy link
Collaborator Author

@kopax unfortunately it can't be included by default. because it will break frequently. any dependency update can result in new error in IE

@kopax
Copy link
Collaborator

kopax commented Oct 10, 2019

Then what's the point? You will redirect IE11 user to a IE11 specific site?

@smashercosmo
Copy link
Collaborator Author

@kopax sorry, didn't understand. The reason why styleguidist doesn't work in IE11 is that it doesn't transpile its dependencies. And sometimes these dependencies contain non-ie-compatible code (like arrow functions). Currently we know the list of these dependencies for the latest styleguidist, so we can transpile them explicitly. But it might break at any moment, when some other dependency introduce non-ie-compatible code.

@abhishekdev
Copy link
Contributor

Then what's the point? You will redirect IE11 user to a IE11 specific site?

@kopax Also to clarify, consider this custom compilation step as an opt-in behavior only required if a projects needs to support IE11. For such projects, this would be the default and no redirect should be required.

@stale
Copy link

stale bot commented Jan 8, 2020

😴 This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week without any further activity. Consider opening a pull request if you still have this issue or want this feature.

@stale stale bot added the wontfix label Jan 8, 2020
@stale stale bot closed this Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants