# 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:
```javascript
const a = 5
export const b = 'foo'
export { a }
```
becomes
```javascript
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][reference] for futher details. In short, you'll want to set your loader options to something like
```javascript
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)
{},
],
],
},
},
},
},
},
],
},
};
```
[documentation]: https://rspack.dev/guide/features/builtin-swc-loader#jscexperimentalplugins
[reference]: https://rspack.dev/config/module#ruleuse