unifiedjs / unified

☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
https://unifiedjs.com
MIT License
4.49k stars 110 forks source link

Browser support #55

Closed jasonqsong closed 5 years ago

jasonqsong commented 5 years ago

The dependency "is-plain-obj" npm package is not compatible with ...... IE

tl;dr is-plain-object seems like a good alternative.

Unlike other packages, "is-plain-obj" is publishing arrow functions without transpiling. It will cause the applications that use IE as the javascript engine failing to load unifiedjs. For my case, it's on-premise MS Word 2019. In addition, although "is-plain-obj" is a 4 line function, it's claiming to support node8+ only. I believe unifiedjs is aiming to support both browser and backends, so a backend only package might not be a good dependency.

FYI, my use case is writing a text processor as an Add-on for MS Word with typescript and unified. My current workaround is using babel to load this package first in my webpack.config.js. Which is obviously an anti-pattern because I'm compiling the package in node_modules

      rules: [
        {
          test: /node_modules\/.*is\-plain\-obj.*\.js$/,
          use: {
            loader: "babel-loader",
            options: { presets: ["@babel/preset-env"] },
          },
        },

Your environment

Steps to reproduce

  1. Create a minimal project
#!/bin/bash
mkdir -p minimal-project/src
cd minimal-project
echo '<script src="main.js"></script>' > index.html
echo 'import unified from "unified"' > src/index.js
yarn add unified webpack webpack-cli webpack-dev-server
./node_modules/.bin/webpack-dev-server --mode development
  1. Open Intenet Explorer and navigate to http://localhost:8080

Then see syntax error from is-plain-obj

image

Expected behaviour

unifiedjs should load correctly

Actual behaviour

The 'is-plain-obj' npm package contains ES6 syntax

ChristianMurphy commented 5 years ago

Unified can be run in the browser, to do so it needs to be bundled (using webpack, rollup, etc) and transpiled (babel, buble, sucrose, etc) (see https://github.com/unifiedjs/unified/issues/34#issuecomment-364196553).

Transpiling dependencies for IE is something that could be covered in a guide https://github.com/unifiedjs/unifiedjs.github.io/issues/7


Which is obviously an anti-pattern because I'm compiling the package in node_modules

Transpiling dependencies is not an anti pattern. It is supported by webpack, rollup, create-react-app, and vue-cli because it is a common need, especially when IE support is a requirement.


PRs adding documentation and guides are welcome!

jasonqsong commented 5 years ago

Sounds good! I just created a super simple guide for it. Wonder if you'd like to accept it :)