Crates.io | swc-export-order |
lib.rs | swc-export-order |
version | 0.1.0 |
created_at | 2025-01-13 15:12:12.933399+00 |
updated_at | 2025-01-13 15:12:12.933399+00 |
description | SWC plugin for injecting export order |
homepage | |
repository | https://github.com/agraven/swc-export-order |
max_upload_size | |
id | 1514727 |
size | 10,685 |
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.
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)
{},
],
],
},
},
},
},
},
],
},
};