create-snowpack-app icon indicating copy to clipboard operation
create-snowpack-app copied to clipboard

Suggest Sucrase plugin

Open a-gerescher opened this issue 4 years ago • 3 comments

Awesome work you have done. May i suggest an sucrase plugin? sucrase.io

Should be possible with the plugin to reduce packages that are installed. babel-core installs a lot of packages. And build time should be faster.

const { transform } = require('sucrase');

module.exports = function plugin(config, options) {
  return {
    defaultBuildScript: "build:js,jsx,ts,tsx",
    build({ contents, filePath, fileContents }) {
      const result = transform(contents || fileContents, 
      {
        transforms: ["imports", "typescript", "jsx"],
        jsxPragma: options.jsxPragma,
        jsxFragmentPragma: options.jsxFragmentPragma,
        production: true,
        filePath: filePath,
        sourceMapOptions: false
      });

      return { result: result.code };
    },
  };
};

imports transform is not needed when files are es6, typescript transform is not needed if project is not typescript... Just a small question at the end: Do you accept custom templates? Is a rollup-plugin wanted?

a-gerescher avatar Jun 09 '20 16:06 a-gerescher

This is great! I think it can start as a community plugin (happy to link to it in the readme if you want to publish yourself) and then if it gets enough usage we can offer official support for it.

FredKSchott avatar Jun 09 '20 19:06 FredKSchott

This would be very kind. As i don't have any knowledge in publishing packages, is this mandatory? If yes, i suppose a normal npm package is enough. Templates are npm packages as well?

a-gerescher avatar Jun 10 '20 07:06 a-gerescher

Yup, you can see the existing packages in this repo for guidance. A plugin package is just a simple package with that plugin file (the code you included above) as the "main" entrypoint.

FredKSchott avatar Jun 10 '20 15:06 FredKSchott