在我的包中使用绝对路径,就像这样:import { Component1, Component2 } from "common/assets";
在本地安装和检查后出现错误:
./node_modules/package/dist/package.js 模块未找到:无法解析 'common/assets' 在 '/home/max/project/node_modules/package/dist' 中
在组装过程中会收到警告:
(!) 未解决的依赖关系 common/helpers(由 src/components/Link/index.ts... 导入)
我的Rollup配置如下:
/* 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;
我可以在我的项目中使用绝对路径吗?如何解决?
../src/common/assets
。对于webpack,我使用resolve
指令作为path.resolve(__dirname, 'src')
来在开发环境中访问它。rollupjs有类似的规则吗? - undefined