gpt4 book ai didi

build - 使用 rollup 解析绝对路径

转载 作者:行者123 更新时间:2023-12-05 08:07:49 25 4
gpt4 key购买 nike

像这样在我的包中使用绝对路径 import { Component1, Component2 } from "common/assets";

本地安装检查后报错

./node_modules/package/dist/package.js Module not found: Can't resolve 'common/assets' in '/home/max/project/node_modules/package/dist'

在装配过程中得到警告

(!) Unresolved dependencies common/helpers (imported by src/components/Link/index.ts...

我的汇总配置

/* eslint-disable flowtype/require-valid-file-annotation, no-console, import/extensions */
import nodeResolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import flow from "rollup-plugin-flow";
import sourceMaps from "rollup-plugin-sourcemaps";

const commonPlugins = [
flow({
pretty: true
}),
sourceMaps(),
nodeResolve({
jsnext: true,
main: true,
browser: true,
extensions: [".ts", ".tsx", ".js", ".jsx"]
}),
babel({
exclude: "node_modules/**"
}),
commonjs({
namedExports: {
react: [
"cloneElement",
"createFactory",
"Component",
"PropTypes",
"createElement",
"createContext"
],
"react-dom": ["render"],
"react-is": ["isElement", "isValidElementType", "ForwardRef"]
}
})
];

const globals = { react: "React", "react-dom": "ReactDOM" };

const configBase = {
input: "./src/index.js",
plugins: commonPlugins
};

const standaloneBaseConfig = {
...configBase,
output: {
file: "dist/package.js",
format: "cjs",
name: "sct",
globals,
sourcemap: true
},
plugins: configBase.plugins
};

export default standaloneBaseConfig;

我可以在我的项目中使用绝对路径吗?如何解决?

最佳答案

你可以使用官方插件:@rollup/plugin-alias .

关于build - 使用 rollup 解析绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53071435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com