dojo-webpack-plugin

raw JSON →
3.0.9 verified Sat Apr 25 auth: no javascript

Webpack plugin for building Dojo 1.x AMD applications with webpack 5. Current stable version is 3.0.9, maintained on GitHub by OpenNTF. Released continuously with bug fixes and security updates. Differentiators: resolves Dojo AMD modules via webpack, supports synchronous and asynchronous require in packed code, embeds a stripped-down Dojo loader at ~1.5KB for runtime require resolution, handles dojo/text, dojo/has, dojo/i18n loaders, and respects loader config (baseUrl, paths, packages, map, aliases). Requires webpack >=5, tapable >=2, webpack-sources >=2. Alternative to using Dojo's own build system with webpack.

error Module not found: Error: Can't resolve 'dojo'
cause Dojo toolkit is not installed or not referenced in loaderConfig.
fix
npm install dojo and add { name: 'dojo', location: 'node_modules/dojo' } to loaderConfig.packages.
error TypeError: DojoWebpackPlugin is not a constructor
cause Using require() without .default when the package exports ESM default.
fix
Use const DojoWebpackPlugin = require('dojo-webpack-plugin').default;
error Error: Dojo loader not found. Ensure Dojo is installed or provide 'loader' option.
cause The plugin cannot locate the Dojo loader source at build time.
fix
Verify Dojo is installed in node_modules/dojo or specify a custom loader path via the 'loader' option in the plugin config.
error Cannot read property 'getChunkModules' of undefined
cause Conflict with mini-css-extract-plugin or other plugins that modify chunk modules.
fix
Upgrade to dojo-webpack-plugin >=3.0.3 which fixes this issue.
breaking Version 3.0.0 only supports webpack 5. Users on webpack 4 must use the v2x branch.
fix Upgrade to webpack 5 or use dojo-webpack-plugin@2.x from the v2x branch.
gotcha The plugin embeds a custom build of the Dojo loader at build time; the Dojo source must be resolvable in node_modules or via loaderConfig. Without it, the build may fail with missing module errors.
fix Ensure the Dojo toolkit is installed (npm install dojo) and referenced in loaderConfig.packages.
gotcha The default export is ESM-only. Using require('dojo-webpack-plugin') without .default returns the module object, not the constructor.
fix Use import syntax or require('dojo-webpack-plugin').default.
deprecated The 'coerceUndefinedToFalse' option is deprecated and may be removed in future releases.
fix Avoid using this option or handle undefined values explicitly in your code.
gotcha The plugin uses a stripped-down loader for runtime require calls; synchronous require with non-static expressions may not work as expected.
fix Use static require expressions or async require for dynamic module loading.
breaking In v3.0.0, support for webpack 4 was dropped; plugin options related to webpack 4 hooks may be ignored.
fix Review plugin options for webpack 5 compatibility; remove any outdated options.
npm install dojo-webpack-plugin
yarn add dojo-webpack-plugin
pnpm add dojo-webpack-plugin

Shows how to configure the plugin in a webpack config with Dojo loader settings including baseUrl, packages, async, locales, and environment.

// webpack.config.js
import DojoWebpackPlugin from 'dojo-webpack-plugin';

export default {
  entry: './src/main.js',
  output: {
    path: './dist',
    filename: 'bundle.js'
  },
  plugins: [
    new DojoWebpackPlugin({
      loaderConfig: {
        baseUrl: './src',
        packages: [
          { name: 'dojo', location: 'node_modules/dojo' },
          { name: 'app', location: '.' }
        ],
        async: true
      },
      environment: { dojoConfig: 'path/to/dojoConfig.js' },
      locales: ['en-us', 'fr']
    })
  ],
  module: {
    rules: [
      { test: /\.html$/, loader: 'raw-loader' }
    ]
  }
};