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

The deep path is incorrect when set preserveModules to be true #20

Open
ihupoo opened this issue Mar 16, 2021 · 4 comments
Open

The deep path is incorrect when set preserveModules to be true #20

ihupoo opened this issue Mar 16, 2021 · 4 comments
Labels
bug Something isn't working PR welcome

Comments

@ihupoo
Copy link

ihupoo commented Mar 16, 2021

I use the keep-imports-with-preserved-modules example and add a folder in src/components 。

The demo is here

See the dist/esm/components/cc/index.js , the import path is incorrect and is same as the import path in dist/esm/components/image.js

@sormy
Copy link
Owner

sormy commented Mar 16, 2021

Please justify what is the actual value and what is expected.

@ihupoo
Copy link
Author

ihupoo commented Mar 17, 2021

I add src/components/cc/index.js base on the keep-imports-with-preserved-modules example

import imageSrc from "../../assets/image.txt"

export const imageX = function () {
  return imageSrc
}

The dist directory structure is like this

dist
├─cjs
│  │  index.js
│  └─components
│      │  image.js
│      └─cc
│          index.js
├─esm
│  │  index.js
│  └─components
│      │  image.js
│      └─cc
│         index.js
└─public
    └─assets
        image.txt

The import path in dist/esm/components/cc/index.js is

import imageSrc from '../../public/assets/image.txt';

but the import path I expected is

import imageSrc from '../../../public/assets/image.txt';

The rollupConfig is same as the keep-imports-with-preserved-modules example

import smartAsset from "rollup-plugin-smart-asset"

export default {
  input: "src/index.js",
  preserveModules: true,
  plugins: [
    smartAsset({
      url: "copy",
      keepImport: true,
      useHash: false,
      keepName: true,
      outputDir: "dist/x",
      assetsPath: "../public/assets",
      extensions: [".txt"]
    })
  ],
  output: [
    { dir: "dist/cjs", format: "cjs" },
    { dir: "dist/esm", format: "esm" }
  ]
}

Version: "rollup": "^2.38.0", "rollup-plugin-smart-asset": "^2.1.1"

@sormy sormy added the bug Something isn't working label Mar 19, 2021
@sormy
Copy link
Owner

sormy commented Mar 19, 2021

The workaround is to put assets folder inside src

@sormy
Copy link
Owner

sormy commented Mar 19, 2021

The plugin doesn't work well when assets are in parent folder from main entry point file that is src/index.js in this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome
Projects
None yet
Development

No branches or pull requests

2 participants