我正在尝试将Ramda用作项目中的模块,以便在我的./app/js
* .js文件中可以执行以下操作:
include map from 'ramda/src/map';
基本上,我希望能够轻松地将Ramda作为模块导入,以便可以访问如上所示的单独功能。我已经将ramda作为模块安装在node_modules
目录中,并且我使用汇总来构建用ES6编写的js文件。
我的rollup.config.js文件如下所示:
import babel from 'rollup-plugin-babel';
import eslint from 'rollup-plugin-eslint';
import commonjs from 'rollup-plugin-commonjs';
export default {
entry: 'app/js/main.js',
dest: 'app/min/main.min.js',
format: 'iife',
sourceMap: 'inline',
plugins: [
eslint({
'exclude': [
'app/css/**'
]
}),
babel(),
commonjs({
include: 'node_modules/**'
})
]
};
我非常感谢有关如何正确设置它以在./app/js
目录中使用它的一些建议。如果问题不清楚,请告诉我。
谢谢。
我能够解决问题。用相同的设置。我要做的就是更改rollup.config.js配置。更详细地讲,我遵循以下步骤:
安装了插件,rollup-plugin-node-resolve
以允许汇总服务第三者模块访问项目文件(例如,Ramda
在node_modules中):
npm install --save-dev rollup-plugin-node-resolve
然后,我必须在以下内容中添加resolve
一个依赖项rollup.config.js
:
在文件的顶部放置:
import resolve from 'rollup-plugin-node-resolve';
plugins
使用以下参数在数组内调用resolve方法:
//...code before
resolve({
jsnext: true,
browser: true,
main: true,
preferBuiltins: false
}),
//...code after
排除node_modules
来自babel
和包括一切commonjs
以确保模块传递到项目作为依赖关系:
//...code before
babel({
exclude: "node_modules/**",
runtimeHelpers: false
}),
commonjs({
include: 'node_modules/**'
})
//...code after
该rollup.config.js
文件最后看起来像这样:
import babel from 'rollup-plugin-babel';
import eslint from 'rollup-plugin-eslint';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
export default {
entry: 'app/js/main.js',
dest: 'app/min/main.min.js',
format: 'iife',
sourceMap: 'inline',
plugins: [
resolve({
jsnext: true,
browser: true,
main: true,
preferBuiltins: false
}),
eslint({
'exclude': [
'app/css/**'
]
}),
babel({
exclude: "node_modules/**",
runtimeHelpers: false
}),
commonjs({
include: 'node_modules/**'
})
]
};
最后对我有用。在./app/js/
目录中的任何文件中,我都可以从Ramda导入特定功能,如下所示:
import {default as map} from 'ramda/src/map';
此外,在完成上述步骤之后,我还能够安装和集成这个令人惊叹的插件,从而使导入特定功能更加容易-babel-plugin-ramda。
然后,您可以以更简单的方式导入特定功能:
import {map, curry} from 'ramda'
多亏了该插件,仅提供了指定的功能。
希望这对遇到过相同问题的任何人有所帮助,或者将来会帮助那些遇到相同问题的人。
干杯。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句