Back to Tamagui

Webpack Guide

code/tamagui.dev/data/docs/guides/webpack.mdx

1.144.41.6 KB
Original Source

First, install Webpack and webpack-cli:

bash
yarn add -D webpack webpack-cli

Then install the Tamagui plugin:

bash
yarn add -D tamagui-loader

Configuration

Add the plugin to your webpack.config.js. If you have a tamagui.build.ts (recommended — see compiler install docs), no options are needed:

tsx
const { TamaguiPlugin } = require('tamagui-loader')

// reads from tamagui.build.ts automatically
config.plugins.push(new TamaguiPlugin())

Or pass options inline:

tsx
const { TamaguiPlugin } = require('tamagui-loader')

config.plugins.push(
  new TamaguiPlugin({
    config: './src/tamagui.config.ts',
    components: ['tamagui'],
  })
)

Or use a minimal manual setup:

tsx
// some stuff for react-native
config.plugins.push(
  new webpack.DefinePlugin({
    process: {
      env: {
        __DEV__: process.env.NODE_ENV === 'development' ? 'true' : 'false',
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    },
  })
)

config.resolve.alias['react-native$'] = 'react-native-web'

// set up web extensions
compiler.options.resolve.extensions = [
  '.web.tsx',
  '.web.ts',
  '.web.js',
  '.ts',
  '.tsx',
  '.js',
]

Usage

To run the server locally, install webpack-dev-server:

bash
yarn add -D webpack-dev-server

Start the server with:

bash
yarn run webpack serve