feat(core): support rollup.config.ts (#28240)
I would like to be able to use rollup.config.ts. Same way it's used by
rollup and vite teams too.
## Current Behavior
Currently nx plugin does not reconize project containing
rollup.config.ts. It expects only {c|m}js files
## Expected Behavior
When project has rollup.config.ts rollup plugin infers build target
automatically. This build target should be able to find the
rollup.config.ts. For that purpose a special [configPlugin
](https://rollupjs.org/command-line-interface/#configplugin-plugin)CLI
parameter should be used
## Related Issue(s)
Feature request [#28226](https://github.com/nrwl/nx/discussions/28226)
---------
Co-authored-by: Colum Ferry <cferry09@gmail.com>
This commit is contained in:
parent
0d1c96085e
commit
f96fda95f4
@ -41,7 +41,8 @@
|
||||
"nx",
|
||||
"typescript",
|
||||
"@swc/core", // Installed to workspace and only used in swc() plugin
|
||||
"postcss"
|
||||
"postcss",
|
||||
"@rollup/plugin-typescript"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@ -29,11 +29,14 @@
|
||||
"migrations": "./migrations.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nx/devkit": "file:../devkit",
|
||||
"@nx/js": "file:../js",
|
||||
"@rollup/plugin-babel": "^6.0.4",
|
||||
"@rollup/plugin-commonjs": "^25.0.7",
|
||||
"@rollup/plugin-image": "^3.0.3",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@rollup/plugin-typescript": "^12.1.0",
|
||||
"autoprefixer": "^10.4.9",
|
||||
"minimatch": "9.0.3",
|
||||
"picocolors": "^1.1.0",
|
||||
@ -42,9 +45,7 @@
|
||||
"rollup-plugin-copy": "^3.5.0",
|
||||
"rollup-plugin-postcss": "^4.0.2",
|
||||
"rollup-plugin-typescript2": "^0.36.0",
|
||||
"tslib": "^2.3.0",
|
||||
"@nx/devkit": "file:../devkit",
|
||||
"@nx/js": "file:../js"
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@ -55,6 +55,61 @@ exports[`@nx/rollup/plugin non-root project should create nodes 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`@nx/rollup/plugin non-root project should create nodes 2`] = `
|
||||
[
|
||||
[
|
||||
"mylib/rollup.config.cts",
|
||||
{
|
||||
"projects": {
|
||||
"mylib": {
|
||||
"root": "mylib",
|
||||
"targets": {
|
||||
"build": {
|
||||
"cache": true,
|
||||
"command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript",
|
||||
"dependsOn": [
|
||||
"^build",
|
||||
],
|
||||
"inputs": [
|
||||
"production",
|
||||
"^production",
|
||||
{
|
||||
"externalDependencies": [
|
||||
"rollup",
|
||||
],
|
||||
},
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Run Rollup",
|
||||
"help": {
|
||||
"command": "npx rollup --help",
|
||||
"example": {
|
||||
"options": {
|
||||
"sourcemap": true,
|
||||
"watch": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"technologies": [
|
||||
"rollup",
|
||||
],
|
||||
},
|
||||
"options": {
|
||||
"cwd": "mylib",
|
||||
},
|
||||
"outputs": [
|
||||
"{workspaceRoot}/mylib/build",
|
||||
"{workspaceRoot}/mylib/dist",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`@nx/rollup/plugin root project should create nodes 1`] = `
|
||||
[
|
||||
[
|
||||
@ -108,3 +163,57 @@ exports[`@nx/rollup/plugin root project should create nodes 1`] = `
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`@nx/rollup/plugin root project should create nodes 2`] = `
|
||||
[
|
||||
[
|
||||
"rollup.config.cts",
|
||||
{
|
||||
"projects": {
|
||||
".": {
|
||||
"root": ".",
|
||||
"targets": {
|
||||
"build": {
|
||||
"cache": true,
|
||||
"command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript",
|
||||
"dependsOn": [
|
||||
"^build",
|
||||
],
|
||||
"inputs": [
|
||||
"production",
|
||||
"^production",
|
||||
{
|
||||
"externalDependencies": [
|
||||
"rollup",
|
||||
],
|
||||
},
|
||||
],
|
||||
"metadata": {
|
||||
"description": "Run Rollup",
|
||||
"help": {
|
||||
"command": "npx rollup --help",
|
||||
"example": {
|
||||
"options": {
|
||||
"sourcemap": true,
|
||||
"watch": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"technologies": [
|
||||
"rollup",
|
||||
],
|
||||
},
|
||||
"options": {
|
||||
"cwd": ".",
|
||||
},
|
||||
"outputs": [
|
||||
"{workspaceRoot}/dist",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
`;
|
||||
|
||||
@ -15,7 +15,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
let context: CreateNodesContext;
|
||||
let cwd = process.cwd();
|
||||
|
||||
describe('root project', () => {
|
||||
describe.each(['js', 'ts'])('root project', (extname) => {
|
||||
const tempFs = new TempFs('test');
|
||||
|
||||
beforeEach(() => {
|
||||
@ -51,7 +51,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
// is that the hash is different after updating the
|
||||
// config file. The actual config read is mocked below.
|
||||
tempFs.createFileSync(
|
||||
'rollup.config.cjs',
|
||||
`rollup.config.c${extname}`,
|
||||
JSON.stringify(rollupConfigOptions)
|
||||
);
|
||||
tempFs.createFileSync('package.json', JSON.stringify({ name: 'mylib' }));
|
||||
@ -77,7 +77,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
it('should create nodes', async () => {
|
||||
// ACT
|
||||
const nodes = await createNodesFunction(
|
||||
['rollup.config.cjs'],
|
||||
[`rollup.config.c${extname}`],
|
||||
{
|
||||
buildTargetName: 'build',
|
||||
},
|
||||
@ -89,7 +89,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('non-root project', () => {
|
||||
describe.each(['js', 'ts'])('non-root project', (extname) => {
|
||||
const tempFs = new TempFs('test');
|
||||
|
||||
beforeEach(() => {
|
||||
@ -125,7 +125,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
// is that the hash is different after updating the
|
||||
// config file. The actual config read is mocked below.
|
||||
tempFs.createFileSync(
|
||||
'mylib/rollup.config.cjs',
|
||||
`mylib/rollup.config.c${extname}`,
|
||||
JSON.stringify(rollupConfigOptions)
|
||||
);
|
||||
tempFs.createFileSync(
|
||||
@ -154,7 +154,7 @@ describe('@nx/rollup/plugin', () => {
|
||||
it('should create nodes', async () => {
|
||||
// ACT
|
||||
const nodes = await createNodesFunction(
|
||||
['mylib/rollup.config.cjs'],
|
||||
[`mylib/rollup.config.c${extname}`],
|
||||
{
|
||||
buildTargetName: 'build',
|
||||
},
|
||||
|
||||
@ -48,7 +48,7 @@ export interface RollupPluginOptions {
|
||||
buildTargetName?: string;
|
||||
}
|
||||
|
||||
const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs}';
|
||||
const rollupConfigGlob = '**/rollup.config.{js,cjs,mjs,ts,cts,mts}';
|
||||
|
||||
export const createNodes: CreateNodes<RollupPluginOptions> = [
|
||||
rollupConfigGlob,
|
||||
@ -182,7 +182,11 @@ async function buildRollupTarget(
|
||||
|
||||
const targets: Record<string, TargetConfiguration> = {};
|
||||
targets[options.buildTargetName] = {
|
||||
command: `rollup -c ${basename(configFilePath)}`,
|
||||
command: `rollup -c ${basename(configFilePath)}${
|
||||
configFilePath.endsWith('ts')
|
||||
? ' --configPlugin @rollup/plugin-typescript'
|
||||
: ''
|
||||
}`,
|
||||
options: { cwd: projectRoot },
|
||||
cache: true,
|
||||
dependsOn: [`^${options.buildTargetName}`],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user