nandorojo / dripsy

🍷 Responsive, unstyled UI primitives for React Native + Web.
https://dripsy.xyz
MIT License
1.99k stars 77 forks source link

Use Dripsy with Vanilla React Native Web App with TypeScript and WebPack #190

Closed aboahab closed 2 years ago

aboahab commented 2 years ago

Hello,

I already used dripsy with expo and it is amazing, but know I want to use it with normal react native + web and typescript, but I did not get it right after several tries.

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const rootDir = path.join(__dirname, '..');
const webpackEnv = process.env.NODE_ENV || 'development';

module.exports = {
  mode: webpackEnv,
  entry: {
    app: path.join(rootDir, './index.web.ts'),
  },
  output: {
    path: path.resolve(rootDir, 'dist'),
    filename: 'app-[hash].bundle.js',
  },
  devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.(tsx|ts|jsx|js|mjs)$/,
        exclude: /node_modules/,
        loader: 'ts-loader',
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.join(__dirname, './index.html'),
    }),
    new webpack.HotModuleReplacementPlugin(),
  ],
  resolve: {
    extensions: [
      '.web.tsx',
      '.web.ts',
      '.tsx',
      '.ts',
      '.web.jsx',
      '.web.js',
      '.jsx',
      '.js',
    ], // read files in fillowing order
    alias: Object.assign({
      'react-native$': 'react-native-web',
    }),
  },

};

I have setup the project as described here https://levelup.gitconnected.com/setup-react-native-web-app-with-typescript-and-webpack-ff79062f53ba

Thanks in advance for the help

nandorojo commented 2 years ago

did you read the web docs: https://www.dripsy.xyz/get-started/web/expo

aboahab commented 2 years ago

Sure but this is only for expo, I want to use it without expo, plain react native

nandorojo commented 2 years ago

You could use those instructions without Expo, since it's just the webpack config.

nandorojo commented 2 years ago

Alternatively, you need a way to transpile dripsy and the @dripsy subpackages.

nandorojo commented 2 years ago

What if you change your exclude statement inside of ts-loader to look like this:

exclude: /node_modules\/(?!(dripsy|@dripsy/gradient|@dripsy/core)\/).*/,
blwinters commented 1 year ago

I ran into something similar (now solved) because I'm using the Storybook addon-react-native-web. For that web environment, instead of an explicit webpack.config.js file, you need to pass the package names in the addon options and Storybook handles the transpilation. (addon docs)

.storybook/main.js

module.exports = {
  stories: ['../src/components/**/*.stories.?(ts|tsx|js|jsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    {
      name: '@storybook/addon-react-native-web',
      options: {
        modulesToTranspile: ['dripsy', '@dripsy'],
      },
    },
  ],
  framework: '@storybook/react',
}