我正在开发一个使用skpm和react-sketchapp的react应用程序。我正在导入一个使用ES.Next 语法的节点模块,所以我需要使用babel来解析该模块目录(node_modules/react-native-calendars )。
skpm充当应用程序的打包器,并使用webpack和babel-loader。skpm中的webpack配置文件被设置为排除node_modules目录。因此,我在node_modules/react-native-calendars目录中得到了一个构建错误。
我认为我可以在我的项目根目录中提供一个webpack.config.js文件,该文件覆盖node_modules/react-native-calendars的node_modules exlcude。
在模块/规则中,我最初有:
include: (/node_modules\/react-native-calendars/),
exclude: (/node_modules/),但我想我需要这样的东西:
exclude: new RegExp (/node_modules\/(?!(react-native-calendars))/),这是整个webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
exclude: new RegExp (/node_modules\/(?!(react-native-calendars))/),
use: {
loader: 'babel-loader',
options: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['transform-runtime', 'transform-class-properties']
}
}
}
]
}
};这里有一个指向回购的链接( /src中只有两个短文件和一个webpack配置):https://github.com/pcooney10/rn-calendar。
编辑
我已经将测试从/\.jsx$/更改为/\.jsx?$/,这是朝着正确方向迈出的一步,但现在似乎/node_modules/react-native-calendars中的导入都没有起作用。我得到了一页日志,上面写着Module not found: Error: Can't resolve 'SomeModule'和Field 'browser' doesn't contain a valid alias configuration。
编辑2:我需要某种path.resolve(__dirname,..)语句吗?
发布于 2017-10-17 19:43:13
你可以简单地这样做:
{
test: /\.jsx?$/,
exclude: /node_modules\/(?!THIS_MODULE|ANOTHER_MODULE)\/).*/
}https://stackoverflow.com/questions/45180008
复制相似问题