Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@weva/babel-plugin-transform-mina-exports

0.0.3 • Public • Published

wrap default exports with Page/Component (or whatever you want)

Usage

yarn add -D @weva/babel-plugin-transform-mina-exports
// src/lib/page
exports.Page = ({ ...props }) => {
  return {
    onLoad(query) {
      this.$query = decode(query)
      props.onLoad.call(this, this.$query)
    },
    ...rest,
  }
}
 
// src/pages/index/index.js
// or 'export default { ... }'
module.exports = {
  onLoad() {
    // ...
  }
}
 
// src/component/a/a.js
module.exports = {
  properties: {},
  /* ... */
}
// babel config
{
  // ...
  plugins: [
    ['@weva/transform-mina-module-exports', {
      rules: [
        {
          files: ['pages/*/*.js'],
          wrap: {
            file: 'src/lib/page',
            exports: 'Page',
          },
        },
        {
          files: ['components/*/*.js'],
          wrap: 'Component',
        },
      ],
    }]
  ]
}
 
// src/pages/index/index.js
require('../../lib/page').Page({
  onLoad() {
    // ...
  }
})
 
// src/components/a/a.js
Component({
  properties: {}
})

License

MIT

Install

npm i @weva/babel-plugin-transform-mina-exports

DownloadsWeekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

2.78 kB

Total Files

3

Last publish

Collaborators

  • avatar