rax-webpack-plugin
raw JSON → 0.6.6 verified Sat Apr 25 auth: no javascript
Webpack plugin for the Rax framework, used to bundle Rax applications with support for multiple target formats (UMD, CMD, bundle, factory). Stable version 0.6.6, with later releases up to v1.2.x in the monorepo. Provides built-in module externalization, polyfill inclusion, and multi-platform output (web, weex, node, React Native). Differentiates from generic webpack plugins by offering Rax-specific features like framework comment injection and duplicate dependency checks. The package is part of the Alibaba Rax project and has a peer dependency on webpack 1–4.
Common errors
error TypeError: RaxPlugin is not a constructor ↓
cause Incorrect import: using default ES import on a CJS module.
fix
Use const RaxPlugin = require('rax-webpack-plugin');
error Cannot find module 'rax-webpack-plugin' ↓
cause Package not installed or missing peer dependencies.
fix
Run npm install --save-dev rax-webpack-plugin and ensure webpack is installed.
error Module parse failed: Unexpected token (1:0) when building ↓
cause Missing required options for RaxPlugin, e.g., target not specified.
fix
Instantiate RaxPlugin with valid options object, e.g., new RaxPlugin({ target: 'umd' }).
Warnings
gotcha Plugin does not support ESM imports; must use CommonJS require(). ↓
fix Use require('rax-webpack-plugin') instead of import.
gotcha BuiltinModules is a static property on RaxPlugin, not exported as default. ↓
fix Access via RaxPlugin.BuiltinModules or destructure const { BuiltinModules } = require('rax-webpack-plugin').
gotcha Specifying both moduleName and globalName is required for UMD target; omitting causes runtime errors. ↓
fix Provide both options when target is 'umd'.
breaking Peer dependency webpack ^1.x.x || ^2.x.x || ^3.x.x || ^4.x.x; webpack 5 not supported. ↓
fix Use webpack 4 or lower, or migrate to alternative plugin.
Install
npm install rax-webpack-plugin yarn add rax-webpack-plugin pnpm add rax-webpack-plugin Imports
- RaxPlugin wrong
import RaxPlugin from 'rax-webpack-plugin';correctconst RaxPlugin = require('rax-webpack-plugin'); - MultiplePlatform wrong
import { MultiplePlatform } from 'rax-webpack-plugin';correctconst { MultiplePlatform } = require('rax-webpack-plugin'); - BuiltinModules wrong
import BuiltinModules from 'rax-webpack-plugin';correctconst { BuiltinModules } = require('rax-webpack-plugin');
Quickstart
const RaxPlugin = require('rax-webpack-plugin');
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
},
plugins: [
new RaxPlugin({
target: 'umd',
moduleName: 'MyApp',
globalName: 'MyApp',
externalBuiltinModules: true,
includePolyfills: false,
}),
],
};