admin管理员组文章数量:1406913
I am trying to publish a library with rollup to build a bundle for other projects to reuse.
But i am having issue with import mapping in the bundle I build, since I am using Path aliases in my source code.
For exmaples
import theme from '@src/styles/modules/theme.module.scss'
import PdfIcon from '@src/assets/icons/pdf.svg'
My rollup config
import resolve from "rollup-plugin-node-resolve"
import babel from "rollup-plugin-babel"
import monjs from "rollup-plugin-monjs"
import typescript from "rollup-plugin-typescript"
import pkg from "./package.json"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
import alias from '@rollup/plugin-alias';
export default [
{
input: "src/index.tsx",
output: [
{
file: pkg.main,
format: "es",
sourcemap: true,
},
],
external: Object.keys(pkg.peerDependencies || {}),
globals: { "styled-ponents": "styled" },
plugins: [
peerDepsExternal(),
babel({
exclude: "node_modules/**",
extensions: [".ts", ".tsx"],
include: ["src/**/*"],
}),
typescript(),
resolve(),
monjs(),
alias({
entries: {
"@src/*": "src/*"
}
})
],
},
]
The bundle i generated
dist
|
index.js
|
index.js.map
When i try to import into other projects and run. I get the error
Module not found: Can't resolve '@src/styles/modules/theme.module.scss'
21 | var core = require('@material-ui/core');
22 | var ExpandMoreIcon = require('@material-ui/icons/ExpandMore');
> 23 | var theme = require('@src/styles/modules/theme.module.scss');
24 | var React = require('react');
25 | var MuiRadioGroup = require('@material-ui/core/RadioGroup');
26 | var icons = require('@material-ui/icons');
Thanks in advance
I am trying to publish a library with rollup to build a bundle for other projects to reuse.
But i am having issue with import mapping in the bundle I build, since I am using Path aliases in my source code.
For exmaples
import theme from '@src/styles/modules/theme.module.scss'
import PdfIcon from '@src/assets/icons/pdf.svg'
My rollup config
import resolve from "rollup-plugin-node-resolve"
import babel from "rollup-plugin-babel"
import monjs from "rollup-plugin-monjs"
import typescript from "rollup-plugin-typescript"
import pkg from "./package.json"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
import alias from '@rollup/plugin-alias';
export default [
{
input: "src/index.tsx",
output: [
{
file: pkg.main,
format: "es",
sourcemap: true,
},
],
external: Object.keys(pkg.peerDependencies || {}),
globals: { "styled-ponents": "styled" },
plugins: [
peerDepsExternal(),
babel({
exclude: "node_modules/**",
extensions: [".ts", ".tsx"],
include: ["src/**/*"],
}),
typescript(),
resolve(),
monjs(),
alias({
entries: {
"@src/*": "src/*"
}
})
],
},
]
The bundle i generated
dist
|
index.js
|
index.js.map
When i try to import into other projects and run. I get the error
Module not found: Can't resolve '@src/styles/modules/theme.module.scss'
21 | var core = require('@material-ui/core');
22 | var ExpandMoreIcon = require('@material-ui/icons/ExpandMore');
> 23 | var theme = require('@src/styles/modules/theme.module.scss');
24 | var React = require('react');
25 | var MuiRadioGroup = require('@material-ui/core/RadioGroup');
26 | var icons = require('@material-ui/icons');
Thanks in advance
Share Improve this question edited Apr 13, 2021 at 3:15 Jackal asked Apr 13, 2021 at 2:59 JackalJackal 5431 gold badge6 silver badges16 bronze badges2 Answers
Reset to default 3Try to move the alias
plugin declaration to the top of the plugin list.
I had the same problem, fixed with this:
alias({ entries: [{ find: /^@src\/(.*)/, replacement: 'src/$1' }] })`
本文标签: javascriptroll up bundle fails to map alias importStack Overflow
版权声明:本文标题:javascript - roll up bundle fails to map alias import - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744986785a2636138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论