swc-export-order 0.1.0

SWC plugin for injecting export order
Documentation
  • Coverage
  • 66.67%
    4 out of 6 items documented0 out of 5 items with examples
  • Size
  • Source code size: 68.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 583.01 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 30s Average build duration of successful builds.
  • all releases: 1m 30s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • agraven/swc-export-order
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • agraven

SWC export order

This is an SWC plugin which injects an exported constant named __namedExportsOrder. This constant is defined as a string array of exported names in the module, in the order they were exported. Thus, the following example:

const a = 5

export const b = 'foo'

export { a }

becomes

const a = 5

export const b = 'foo'

export { a }
export const __namedExportsOrder = ['b', 'a']

As you can see, the order is dictated by when a name is exported, not by when it is defined.

Using the plugin

The plugin targets swc_core 5.0, meaning that it supports @swc/core 1.9. See https://plugins.swc.rs/ for details. Assuming you're using rspack, you can follow its documentation for an example for adding a plugin. You can also consult its reference for futher details. In short, you'll want to set your loader options to something like

module.exports = {
  module: {
    rules: [
      {
        // Which modules should be match
        test: /\.js$/,
        use: {
          loader: 'builtin:swc-loader',
          options: {
            jsc: {
              experimental: {
                plugins: [
                  [
                    // Name of NPM package
                    'swc-export-order',
                    // Plugin configuration (not used for this plugin, may be subject to change)
                    {},
                  ],
                ],
              },
            },
          },
        },
      },
    ],
  },
};