dazinator / NetPack

.Net Core library, for runtime processing of static files such as typescript, js, css etc.
13 stars 2 forks source link

Rollup FluentAPI extensions for common plugins #33

Closed dazinator closed 6 years ago

dazinator commented 6 years ago

I provide a fluent API for importing modules, and adding rollup plugins to the rollup build script. However this fluent API is for the general case, i.e adding any version of any plugin, and then configuring its options based on dynamic. You have to know what options to set for each plugin and its down to you to set them correctly.

I am going to add some extension methods to the fluent configuration of rollup, for specific plugins that I have found useful. I expect this will grow over time.

Starting with:

This should pave the way for more in future.

dazinator commented 6 years ago

To configure rollup-plugin-amd and module-lookup-amd, instead of this:

options.AddImport((a) =>
{
          a.RequiresNpmModule("module-lookup-amd", "5.0.1")
            .HasDefaultExportName("lookup");   // only imported into the script as default export name, won't be included in rollupjs plugins list, but other plugin config could reference it.                                       
})
.AddPlugin((a) =>
 {
         a.RequiresNpmModule("rollup-plugin-amd", "3.0.0")
           .HasOptionsOfKind(OptionsKind.Object, (amdPluginOptions) =>
           {
                 amdPluginOptions.rewire = "FUNCfunction (moduleId, parentPath) { return lookup({ partial: moduleId, filename: parentPath, config: {baseUrl: '/amd'} }); }FUNC";    
          });                             
});

You can now do this:


 options
    .ImportModuleLookupAmd()   
    .AddPluginAmd((amdPluginOptions) =>
    {
         amdPluginOptions.RewireFunction("function (moduleId, parentPath) { return lookup({ partial: moduleId, filename: parentPath, config: {baseUrl: '/amd'} }); }");
    })