Different main entry point in package.json for node and browser

后端 未结 4 1781
我在风中等你
我在风中等你 2021-02-20 16:02

In isomorphic react app I have myModule which should behave differently on node and browser environments. I would like configure this split point i

4条回答
  •  我寻月下人不归
    2021-02-20 16:15

    The behavior is standardized here: https://github.com/defunctzombie/package-browser-field-spec

    Although this specification is unofficial, many Javascript bundlers follow it, including Webpack, Browserify, and the React Native packager. The browser field not only allows you to change your module entry point, but to also replace or ignore individual files within your module. It's quite powerful.

    Since Webpack bundles code for the web by default, you need to manually disable the browser field if you want to use Webpack for your server build. You can do that using the target config option to do this: https://webpack.js.org/concepts/targets/

提交回复
热议问题