Skip to content

Commit

Permalink
Merge pull request #70 from atom-community/override-by-default
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Aug 12, 2021
2 parents e4b294f + 1a87dce commit 73d8a64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,32 @@ terser (in production)
replace (in production)
```

### Override Default Options for the plugins `[name, overriddenOptions, true]`
### Override Default Options for the plugins `[name, overriddenOptions]`

You can pass an input plugin with the overridden options using the `[name, overriddenOptions, true]` syntax.
You can pass an input plugin with the overridden options using the `[name, overriddenOptions]` syntax.

```ts
const plugins = createPlugins([
["ts", { tsconfig: "./lib/tsconfig.json" }, true], // third element makes the config merge to and override the default options
"js",
])
const plugins = createPlugins([["ts", { tsconfig: "./lib/tsconfig.json" }], "js"])
```

The difference with the next syntax is that these are merged into the default options and if there is a config with the same name, they override it, but the next syntax completely replaces the default options.
### Completely New Options for the plugins `[name, newOptions, false]`

### Completely New Options for the plugins `[name, newOptions]`

You can pass an input plugin with their supported option using the `[name, newOptions]` syntax:
You can pass an input plugin with their supported option using the `[name, newOptions, false]` syntax:

```ts
const plugins = createPlugins([
["ts", { tsconfig: "./lib/tsconfig.json", noEmitOnError: false, module: "ESNext" }],
["ts", { tsconfig: "./lib/tsconfig.json", noEmitOnError: false, module: "ESNext" }, false],
"js",
])
```

Passing false as the third argument results in discarding the `rollup-config-atomic` built-in options.

### Adding New Extra Plugins

For adding extra plugins, you can pass them in array to the second argument
For adding extra plugins, you can simply concatenate your plugins with the output of `createPlugins`

```ts
import multyentry from "@rollup/plugin-multi-entry"
createPlugins(["ts"], [multyentry()])
const plugins = [...createPlugins(["ts"]), multyentry()]
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-visualizer": "^5.5.2",
"tslib": "^2.3.0",
"tslib": "^2.3.1",
"rollup": "^2",
"@babel/core": "^7",
"typescript": "^4"
Expand Down
34 changes: 7 additions & 27 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export function createPlugins(

// extra plugins
if (extraPlugins !== undefined && typeof extraPlugins === "object" /*array*/) {
console.warn(
"Passing extra plugins to `createPlugins` is deprecated. Instead concatenate the output of `createPlugins` with your extra plugins."
)
try {
plugins.push(...extraPlugins)
} catch (e) {
Expand Down Expand Up @@ -225,7 +228,10 @@ export function createPlugins(
if (typeof inputPluginsNames[index] === "string") {
// plugin name only
plugins.push(pluginFunction(pluginDefaultOptions))
} else if (typeof inputPluginsNames[index][2] === "boolean" && inputPluginsNames[index][2] === true) {
} else if (inputPluginsNames[index].length == 3 && inputPluginsNames[index][2] === false) {
// plugin with options from scratch
plugins.push(pluginFunction(inputPluginsNames[index][1]))
} else {
// plugin with options that override pluginDefaultOptions
const pluginOptions = inputPluginsNames[index][1]
plugins.push(
Expand All @@ -235,9 +241,6 @@ export function createPlugins(
: { ...pluginDefaultOptions, pluginOptions }
)
)
} else {
// plugin with options
plugins.push(pluginFunction(inputPluginsNames[index][1]))
}
} else if (includeByDefault) {
const pluginFunction = getPluginFunction(require(moduleName), prop)
Expand All @@ -247,26 +250,3 @@ export function createPlugins(

return plugins
}

/** @deprecated Use default Rollup syntax - this function will be removed in the next major version */
export function createConfig(
input: string | Array<string> = "src/main.ts",
output_dir: string = "dist",
output_format = "cjs",
externals: Array<string> = ["atom", "electron"],
plugins = createPlugins()
) {
return {
input: input,
output: [
{
dir: output_dir,
format: output_format,
sourcemap: true,
},
],
// loaded externally
external: externals,
plugins: plugins,
}
}

0 comments on commit 73d8a64

Please sign in to comment.