我有一个carousel文件,我想在其中获取index.js和构建block.build.js,所以我webpack.config.js的:
var config = {
entry: './index.js',
output: {
path: __dirname,
filename: 'block.build.js',
},
devServer: {
contentBase: './Carousel'
},
module : {
rules : [
{
test: /.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['react', 'es2015'],
plugins: ['transform-class-properties']
}
}
]
}
};
module.exports = config;
Run Code Online (Sandbox Code Playgroud)
在package.json下面,我用的是:
{
"name": "carousel",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"@babel/core": "^7.0.0-beta.40",
"babel-cli": "^6.26.0",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"babel-preset-react": "^6.24.1",
"cross-env": …Run Code Online (Sandbox Code Playgroud) 我试着在一个旧项目中使用Babel-loader,我注意到有关babel加载器何时处理包装对象的一些问题,这是它的默认行为吗?我不确定这是一个错误还是我做错了什么,我在谷歌上找不到它,所以这是我的最后一个资源.
我是否需要更改代码才能使其正常工作?
这是我目前的规格:Webpack:3.19.0 babel/core:7.0.0-beta.34 babel-loader:8.0.0-beta.0
如果需要,请参考我的packages.json:
http://paste.ubuntu.com/26187880/
我试着加载包含在函数中的单个文件:
http://paste.ubuntu.com/26187814/
恢复,旧的,这样建立:
( window.global = { } )();
Run Code Online (Sandbox Code Playgroud)
这是我的webpack配置:
const webpackConfig = {
context: __dirname,
entry: {
app: '../../JavaScript/Namespacing.js'
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
}
}
]
},
output: {
path: __dirname + "/../../static/js",
filename: "[name].js"
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
Plugin/Preset files are not allowed to export objects, only functions.
那么,我错过了什么吗?
谢谢你的帮助.
更新react-native后我收到此错误"^0.56.0":
bundling failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/ben/vepo/frontend/node_modules/babel-preset-flow/lib/index.js
Run Code Online (Sandbox Code Playgroud)
我尝试做类似于最高投票答案的事情,而不是babel-preset-flow:
https://github.com/babel/babel-loader/issues/540
.babelrc:
"presets": ["react-native", "flow", "@babel/preset-flow"]
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"name": "vepo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"rnpm": {
"assets": [
"./app/fonts"
]
},
"jest": {
"preset": "react-native",
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
}
},
"dependencies": {
"@babel/preset-flow": "^7.0.0-beta.52",
"@babel/preset-react": "^7.0.0-beta.52",
"babel-preset-react-native": "^4.0.0",
"flow-typed": "^2.4.0",
"generator-rn-toolbox": "^2.2.0",
"imagemagick": "^0.1.3",
"immutable": "4.0.0-rc.9",
"metro-bundler": "^0.22.1",
"native-base": …Run Code Online (Sandbox Code Playgroud) 我已将我的应用程序迁移到babel 7 beta版,除了测试之外,一切似乎都有效.我想我已经阅读了所有内容,但我仍然收到此错误:
●测试套件无法运行
Run Code Online (Sandbox Code Playgroud)Requires Babel "^7.0.0-0", but was loaded with "6.26.0". If you are sure you have a compatible version of @babel/core, it is likely您的构建过程中的某些内容正在加载错误的版本.检查这个错误的堆栈跟踪,以寻找没有提到"@通天/芯"或"巴别塔芯",看看有什么在呼唤通天塔中的第一项.
Run Code Online (Sandbox Code Playgroud)at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11) at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11) at _default (node_modules/@babel/plugin-proposal-class-properties/lib/index.js:81:7) at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12 at Array.map (<anonymous>)测试套房:8次失败,共8次
babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-flow"
],
"plugins": [
["module-resolver", {
"alias": {
"static": "./static",
"common": "./src/common",
"data": "./src/data"
}
}],
["styled-jsx/babel", { "plugins": ["styled-jsx-plugin-sass"] }],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-syntax-dynamic-import"
]
}
Run Code Online (Sandbox Code Playgroud)
devDependencies
"devDependencies": {
"@babel/cli": "^7.0.0-beta.49",
"@babel/core": "^7.0.0-beta.49", …Run Code Online (Sandbox Code Playgroud) 需要一些帮助,我从左侧字段中得到一个奇怪的错误,我无法调试.在我在另一台Mac上设置我的react本机项目后,这个项目成功捆绑到昨天.
我想知道它是否来自npm软件包的版本我必须重新安装.
任何方向都会有所帮助,它始终是最难设置的,因为你很少这么做...
我的babelrc文件如下 -
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
还有我的package.json
{
"name": "hancho_frontend",
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~27.0.0",
"react-native-scripts": "^1.14.1",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo/vector-icons": "^6.2.0",
"axios": "^0.18.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-upgrade": "0.0.19",
"color": "^2.0.0",
"expo": "^27.1.0",
"hoist-non-react-statics": "^2.3.0", …Run Code Online (Sandbox Code Playgroud) 嗨,请帮助我理解设置babel配置.babelrc与webpack加载器选项之间的区别,将其插入package.json.
例如,如果我将预设置于webpack babel-loader选项vs package.json或单独的.babelrc配置文件中会有什么不同吗?
在webpack配置中:
{
test: /\.(js|jsx|mjs)$/,
loader: require.resolve('babel-loader'),
options: {
"presets": [
"react-app"
]
},
},
Run Code Online (Sandbox Code Playgroud)
在包json中:
"babel": {
"presets": [
"react-app"
]
},
Run Code Online (Sandbox Code Playgroud) babel ×5
webpack ×3
babel-loader ×2
javascript ×2
react-native ×2
babel-jest ×1
babeljs ×1
flowtype ×1
jestjs ×1
package.json ×1
reactjs ×1