Skip to content
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

Rollup plugin enhancement #8575

Closed
linbudu599 opened this issue Jan 18, 2022 · 4 comments
Closed

Rollup plugin enhancement #8575

linbudu599 opened this issue Jan 18, 2022 · 4 comments
Labels
outdated scope: react Issues related to React support for Nx stale type: feature

Comments

@linbudu599
Copy link
Contributor

Description

There is now room for a number of enhancements to the rollup plugin, including but not limited to:

  • Support ESM in rollupConfig(Rollup configuration does not support es6 imports #8459 )
  • Further and more detailed documentation, such as schema-related descriptions, and in particular the function entry descriptions for the rollupConfig configuration export (currentConfig and options).
  • Support .ts for rollupConfig, with corresponding typing support(type RollupConfigFactory = (...) => ValidateRollupConfig), for .js file we can also use JSDoc to provide typing tips from IDE(just as how snowpack does), like /** @type {import("@nrwl/web").RollupConfigFactory } */.
  • Generator support, for example, use nx g @nrwl/web:rollup exist-web-app --rollupConfig=rollup.config.ts to add a section of target configuration using @nrwl/web:rollup as build executor.
  • Incorrect build output (@nrwl/web:rollup produces the wrong output #8475 >>> fix(web): optimized rollup output logic #8526 )
  • ... more to be discovered

Motivation

Suggested Implementation

Alternate Implementations

@vsavkin vsavkin added the scope: react Issues related to React support for Nx label Jan 20, 2022
@vadistic
Copy link

vadistic commented Jan 30, 2022

I'm using fully specified ESM import paths. @nrwl/web can handle those with babel, but not with swc.

It seem to be supported by swc/spack - but not configured for rollups' commonjs & node-resolve plugins. Idk.

swc-project/swc#3043

    "build": {
      "executor": "@nrwl/web:rollup",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/libs/my-lib",
        "tsConfig": "libs/my-lib/tsconfig.lib.json",
        "project": "libs/my-lib/package.json",
        "entryFile": "libs/my-lib/src/index.ts",
        "external": ["react/jsx-runtime"],
        "rollupConfig": "@nrwl/react/plugins/bundle-rollup",
        "compiler": "swc"
      }
    },
// index.ts
import { abort } from './two.js';

// two.ts
export function two() {};
[!] Error: unfinished hook action(s) on exit:
(commonjs) resolveId "./two.js" "/home/vadistic/work/my-project/libs/my-lib/src/index.ts"
(node-resolve) resolveId "./two.js" "/home/vadistic/work/my-project/libs/my-lib/src/index.ts"

@perjerz
Copy link

perjerz commented Apr 12, 2022

There is issue when you try import other libray files to app that use @nrwl/web:rollup (babel) as executor. Ex. // apps/bundler-js/src/main.ts

// apps/bundler-js/src/main.ts
import '../../../libs/shared-assets-backend/generator/main';

The error will be shown as

Error during bundle: /Users/xxx/yyy/apps/bundler-js/src/main.ts(2,8): semantic error TS6059: File '/Users/xxx/yyy/libs/shared-assets-backend/generator/main.ts' is not under 'rootDir' '/Users/xxx/yyy/apps/bundler-js/src'. 'rootDir' is expected to contain all source files.

The rootDir is set by entryFile folder.


 "projectType": "application",
  "root": "apps/bundler-js",
  "sourceRoot": "apps/bundler-js/src",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nrwl/web:rollup",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "project": "apps/bundler-js/package.json",
        "entryFile": "apps/bundler-js/src/main.ts", // <-------------- entry Folder = apps/bundler-js/src
        "tsConfig": "apps/bundler-js/tsconfig.gulp.json",
        "outputPath": "dist/apps/bundler-js",
        "format": ["esm", "cjs"],
        "deleteOutputPath": true,

You can see the source code below.

export function normalizeWebRollupOptions(
options: WebRollupOptions,
root: string,
sourceRoot: string
): NormalizedWebRollupOptions {
const entryFile = `${root}/${options.entryFile}`;
const entryRoot = dirname(entryFile);

To fix this problem, the entryRoot has to be root folder by default.

The workaround is to move main.ts to root project. and configure project.json and fix entryFile as below.

"options": {
        "project": "apps/bundler-js/package.json",
        "entryFile": "main.ts",

@github-actions
Copy link

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx stale type: feature
Projects
None yet
Development

No branches or pull requests

4 participants