storybookjs / addon-react-native-web

Build react-native-web projects in Storybook for React
MIT License
83 stars 24 forks source link

Update webpack.ts for NativeWind v4 #81

Closed panzacoder closed 9 months ago

panzacoder commented 10 months ago

Added an option to pass in custom options for babel/preset-react, which is required in order to set the importSource for Nativewind v4.

I believe this is the root of these issues:

panzacoder commented 10 months ago

đź‘‹ You very much may want to solve this in a different way. After finding this I was able to equally solve the problem by updating my babelPlugins config like this:

{
      name: getAbsolutePath('@storybook/addon-react-native-web'),
      options: {
        projectRoot,
        modulesToTranspile: [
          'app', // this is my local monorepo package
          'react-native',
          'react-native-web',
          'solito',
          'moti',
          'react-native-reanimated',
          'react-native-css-interop',
          'nativewind',
          'react-native-gesture-handler',
        ],
        babelPlugins: [
          'react-native-reanimated/plugin',
          [
            '@babel/plugin-transform-react-jsx',
            {
              runtime: 'automatic',
              importSource: 'nativewind',
            },
          ],
        ],
      },
    },

The key line being the change to the @babel/plugin-transform-react-jsx. I tried MANY ways of configuring this for babel otherwise, but this is the only method that would work in order to make the transformation keep the NativeWind classNames intact.

dannyhw commented 9 months ago

@panzacoder I've updated this pr with some more changes to now allow babel presets and also to pass options to the react native preset

socket-security[bot] commented 9 months ago

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@alloc/quick-lru@5.2.0 None 0 14.1 kB aleclarson
npm/any-promise@1.3.0 None 0 22.2 kB kevinbeaty
npm/autoprefixer@10.4.17 environment Transitive: filesystem, shell +12 2.91 MB ai
npm/babel-plugin-tester@11.0.4 Transitive: environment, eval, filesystem, shell, unsafe +56 12.2 MB xunnamius
npm/camelcase-css@2.0.1 None 0 4.05 kB stevenvachon
npm/core-js@3.35.1 environment, eval, filesystem 0 1.21 MB zloirock
npm/didyoumean@1.2.2 None 0 17.3 kB dcporter
npm/dlv@1.1.3 None 0 5.8 kB developit
npm/fraction.js@4.3.7 None 0 86.2 kB infusion
npm/jiti@1.21.0 environment, filesystem, unsafe 0 1.91 MB pi0
npm/lightningcss-freebsd-x64@1.22.0 None 0 9.62 MB devongovett
npm/lilconfig@2.1.0 filesystem 0 16.6 kB antonk52
npm/nativewind@4.0.23 Transitive: environment, eval, filesystem, network, shell, unsafe +618 715 MB marklawlor
npm/normalize-range@0.1.2 None 0 7.77 kB james.talmage
npm/object-hash@3.0.0 None 0 58.9 kB addaleax
npm/postcss-import@16.0.0 Transitive: environment, filesystem +12 527 kB ryanzim
npm/postcss-js@4.0.1 Transitive: environment +4 240 kB ai
npm/postcss-load-config@4.0.2 environment, unsafe Transitive: filesystem, shell +39 445 MB ai
npm/postcss-loader@8.1.0 Transitive: environment, eval, filesystem, network, shell, unsafe +103 52.9 MB ai, evilebottnawi, jhnns, ...1 more
npm/postcss-nested@6.0.1 Transitive: environment +6 450 kB ai
npm/react-native-css-interop@0.0.22 Transitive: environment, eval, filesystem, network, shell, unsafe +617 715 MB marklawlor
npm/read-cache@1.0.0 filesystem +1 10.2 kB trysound
npm/tailwindcss@3.4.1 environment, filesystem Transitive: shell, unsafe +106 456 MB adamwathan
npm/thenify-all@1.6.0 None +2 36.7 kB dead_horse
npm/thenify@3.3.1 None +1 30.1 kB dead_horse

đźš® Removed packages: npm/@types/d3-array@3.2.1, npm/@types/d3-color@3.1.3, npm/@types/d3-ease@3.0.2, npm/@types/d3-interpolate@3.0.4, npm/@types/d3-path@3.0.2, npm/@types/d3-scale@4.0.8, npm/@types/d3-shape@3.1.6, npm/@types/d3-time@3.0.3, npm/@types/d3-timer@3.0.2, npm/d3-array@3.2.4, npm/d3-color@3.1.0, npm/d3-ease@3.0.1, npm/d3-format@3.1.0, npm/d3-interpolate@3.0.1, npm/d3-path@3.1.0, npm/d3-scale@4.0.2, npm/d3-shape@3.2.0, npm/d3-time-format@4.1.0, npm/d3-time@3.1.0, npm/d3-timer@3.0.1, npm/d3-voronoi@1.1.4, npm/delaunator@4.0.1, npm/delaunay-find@0.0.6, npm/internmap@2.0.3, npm/json-stringify-safe@5.0.1, npm/react-fast-compare@3.2.2, npm/victory-area@36.9.1, npm/victory-axis@36.9.1, npm/victory-bar@36.9.1, npm/victory-box-plot@36.9.1, npm/victory-brush-container@36.9.1, npm/victory-brush-line@36.9.1, npm/victory-candlestick@36.9.1, npm/victory-canvas@36.9.1, npm/victory-chart@36.9.1, npm/victory-core@36.9.1, npm/victory-create-container@36.9.1, npm/victory-cursor-container@36.9.1, npm/victory-errorbar@36.9.1, npm/victory-group@36.9.1, npm/victory-histogram@36.9.1, npm/victory-legend@36.9.1, npm/victory-line@36.9.1, npm/victory-native@40.0.3, npm/victory-pie@36.9.1, npm/victory-polar-axis@36.9.1, npm/victory-scatter@36.9.1, npm/victory-selection-container@36.9.1, npm/victory-shared-events@36.9.1, npm/victory-stack@36.9.1, npm/victory-tooltip@36.9.1, npm/victory-vendor@36.9.1, npm/victory-voronoi-container@36.9.1, npm/victory-voronoi@36.9.1, npm/victory-zoom-container@36.9.1, npm/victory@36.9.1

View full report↗︎

socket-security[bot] commented 9 months ago

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/@alloc/quick-lru@5.2.0, npm/any-promise@1.3.0, npm/autoprefixer@10.4.17, npm/babel-plugin-tester@11.0.4, npm/camelcase-css@2.0.1, npm/core-js@3.35.1, npm/cosmiconfig@9.0.0, npm/didyoumean@1.2.2, npm/dlv@1.1.3, npm/fraction.js@4.3.7, npm/jiti@1.21.0, npm/lightningcss-darwin-arm64@1.22.0, npm/lightningcss-darwin-x64@1.22.0, npm/lightningcss-freebsd-x64@1.22.0, npm/lightningcss-linux-arm-gnueabihf@1.22.0, npm/lightningcss-linux-arm64-gnu@1.22.0, npm/lightningcss-linux-arm64-musl@1.22.0, npm/lightningcss-linux-x64-gnu@1.22.0, npm/lightningcss-linux-x64-musl@1.22.0, npm/lightningcss-win32-x64-msvc@1.22.0, npm/lightningcss@1.22.0, npm/lilconfig@2.1.0, npm/lilconfig@3.0.0, npm/nativewind@4.0.23, npm/normalize-range@0.1.2, npm/object-hash@3.0.0, npm/pify@2.3.0, npm/postcss-import@15.1.0, npm/postcss-import@16.0.0, npm/postcss-js@4.0.1, npm/postcss-load-config@4.0.2, npm/postcss-loader@8.1.0, npm/postcss-nested@6.0.1, npm/react-native-css-interop@0.0.22, npm/read-cache@1.0.0, npm/strip-indent@3.0.0, npm/tailwindcss@3.4.1, npm/thenify-all@1.6.0, npm/thenify@3.3.1

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

panzacoder commented 9 months ago

@panzacoder I've updated this pr with some more changes to now allow babel presets and also to pass options to the react native preset

@dannyhw Just looked through the changes, looks good to me, and looks like you added nativewind support to the .storybook/main.js. Is that for your example or are you planning to ship that support zero-config?

dannyhw commented 9 months ago

@panzacoder thats just adding it to the example so that its tested

dannyhw commented 9 months ago

@SocketSecurity ignore-all