-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce CLI --plugin support #3379
Changes from 5 commits
ead93ed
5efed08
a179256
b3543a3
d6d94da
721beb8
dbd2f3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,7 @@ Many options have command line equivalents. In those cases, any arguments passed | |
-m, --sourcemap Generate sourcemap (`-m inline` for inline map) | ||
-n, --name <name> Name for UMD export | ||
-o, --file <output> Single output file (if absent, prints to stdout) | ||
-p, --plugin <plugin> Use the plugin specified (may be repeated) | ||
-v, --version Show version number | ||
-w, --watch Watch files in bundle and rebuild on changes | ||
--amd.id <id> ID for AMD module (default is anonymous) | ||
|
@@ -268,6 +269,47 @@ The flags listed below are only available via the command line interface. All ot | |
|
||
Print the help document. | ||
|
||
#### `-p <plugin>`, `--plugin <plugin>` | ||
|
||
Use the specified plugin. There are several ways to specify plugins here: | ||
|
||
- Via a relative path: | ||
|
||
``` | ||
rollup -i input.js -f es -p ./my-plugin.js | ||
``` | ||
|
||
The file should export a plugin object or a function returning such an object. | ||
- Via the name of a plugin that is installed in a local or global `node_modules` folder: | ||
|
||
``` | ||
rollup -i input.js -f es -p @rollup/plugin-node-resolve | ||
``` | ||
|
||
If the plugin name does not start with `rollup-plugin-` or `@rollup/plugin-`, Rollup will automatically try adding these prefixes: | ||
|
||
``` | ||
rollup -i input.js -f es -p node-resolve | ||
``` | ||
|
||
- Via an inline implementation: | ||
|
||
``` | ||
rollup -i input.js -f es -p '{transform: c => "/* TEST */" + c} | ||
``` | ||
|
||
If you want to load more than one plugin, you can repeat the option or supply a comma-separated list of names: | ||
|
||
``` | ||
rollup -i input.js -f es -p node-resolve -p commonjs,json | ||
``` | ||
|
||
By default, plugins that export functions will be called with no argument to create the plugin. You can however pass a custom argument as well: | ||
|
||
``` | ||
rollup -i input.js -f es -p "terser={output: {beautify: true, indent_level: 2}}"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo - stray trailing backtick |
||
``` | ||
|
||
#### `-v`/`--version` | ||
|
||
Print the installed version number. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
description: 'CLI --plugin /absolute/path', | ||
skipIfWindows: true, | ||
command: `echo 'console.log(VALUE);' | rollup -p "\`pwd\`/my-plugin={VALUE: 'absolute', ZZZ: 1}"` | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("absolute"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function(options) { | ||
if (options === void 0) options = {}; | ||
return { | ||
transform(code) { | ||
// dumb search and replace for test purposes | ||
for (var key in options) { | ||
const rx = new RegExp(key, 'g'); | ||
const value = JSON.stringify(options[key]); | ||
code = code.replace(rx, value); | ||
} | ||
return code; | ||
} | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
description: 'advanced CLI --plugin functionality with rollup config', | ||
skipIfWindows: true, | ||
command: `rollup -c -p node-resolve,commonjs -p "terser={output: {beautify: true, indent_level: 2}}"` | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
|
||
var t = function() { | ||
function t(t) { | ||
this.x = t; | ||
} | ||
return t.prototype.output = function() { | ||
var t; | ||
t = this.x, console.log(t); | ||
}, t; | ||
}(); | ||
|
||
new t(123).output(), exports.Bar = t; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var t = function() { | ||
function t(t) { | ||
this.x = t; | ||
} | ||
return t.prototype.output = function() { | ||
var t; | ||
t = this.x, console.log(t); | ||
}, t; | ||
}(); | ||
|
||
new t(123).output(); | ||
|
||
export { t as Bar }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {Foo} from "foo"; | ||
var foo = new Foo(123); | ||
foo.output(); | ||
export {Foo as Bar}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const buble = require('rollup-plugin-buble'); | ||
|
||
export default { | ||
input: 'main.js', | ||
plugins: [ | ||
buble() | ||
], | ||
output: [ | ||
{ | ||
file: '_actual/cjs.js', | ||
format: 'cjs' | ||
}, | ||
{ | ||
file: '_actual/es.js', | ||
format: 'esm' | ||
} | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
description: 'basic CLI --plugin functionality', | ||
command: `rollup main.js -f cjs --plugin rollup-plugin-buble` | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var Bar = function Bar(x) { | ||
this.x = value; | ||
}; | ||
Bar.prototype.value = function value () { | ||
return this.x; | ||
}; | ||
var bar = new Bar(123); | ||
console.log(bar.value()); | ||
|
||
exports.Bar = Bar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class Bar { | ||
constructor(x) { | ||
this.x = value; | ||
} | ||
value() { | ||
return this.x; | ||
} | ||
} | ||
var bar = new Bar(123); | ||
console.log(bar.value()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { assertStderrIncludes } = require('../../../../utils.js'); | ||
|
||
module.exports = { | ||
description: 'unknown CLI --plugin results in an error', | ||
skipIfWindows: true, | ||
command: `echo "console.log(123);" | rollup --plugin foobar`, | ||
error(err) { | ||
assertStderrIncludes(err.message, '[!] Error: Cannot load plugin "foobar"'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { assertStderrIncludes } = require('../../../../utils.js'); | ||
|
||
module.exports = { | ||
description: 'invalid CLI --plugin argument format', | ||
skipIfWindows: true, | ||
command: `echo "console.log(123);" | rollup --plugin 'foo bar'`, | ||
error(err) { | ||
assertStderrIncludes(err.message, '[!] Error: Invalid --plugin argument format: "foo bar"'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
description: 'CLI --plugin object', | ||
skipIfWindows: true, | ||
command: `echo 'console.log(42);' | rollup -f cjs -p '{transform: c => c + String.fromCharCode(10) + c}'` | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo - need a trailing single quote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the example doesn't work unless you add a newline - rollup drops the comment otherwise:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is a bit more interesting - it's up to you:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps:
which would show embedded
\0
(nils) for other plugins.Try running the following and then again without the newline after the comment:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Without the newline, Rollup only keeps the comment if the first line is preserved, which was the case for my test call 😉 With the newline, it is always preserved as it is considered a banner.
I will change to using your example 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I also consistenly used single quotes around both examples because otherwise, Bash might do variable expansions or let hell break loose when you use backticks...