草庐IT

Babel-loader

全部标签

javascript - webpack.config.babel.js中使用 'import'报错

(function(exports,require,module,__filename,__dirname){importpathfrom'path'^^^^^^SyntaxError:Unexpectedtokenimport当我使用webpack-dev-server--hot时出现此错误。出现这种情况好像是因为它无法读取import或者webpack不支持import。我尝试使用babel-register但它不起作用。有什么办法可以解决这个问题吗?请引用下面的代码。webpack.config.babel.jsimportpathfrom'path'importwebpackf

javascript - Babel ES6 导入错误,SyntaxError : Unexpected token import

我正在尝试设置一个基本的模块化程序,但我似乎遇到了导入模块的问题。我尝试导入我的自定义模块,但出现以下错误:(function(exports,require,module,__filename,__dirname){importtestStepfrom'testStep';^^^^^^SyntaxError:Unexpectedtokenimport导致问题的代码:测试用例.jsimporttestStepfrom'testStep';testStep.hello();测试步骤.jsvartestStep={hello:hello,};varhello=()=>{console.lo

javascript - 从 7 升级到 Babel-loader 8?我需要改变什么?

我正在尝试从版本7升级到版本8。但我遇到了一些错误。我想我需要升级一些东西但不确定是什么这就是我的包(我删除了与我的问题无关的插件)"dependencies":{"babel-plugin-emotion":"^9.2.5","babel-polyfill":"^6.26.0","http-proxy-middleware":"^0.18.0","koa-connect":"^2.0.1","koa-router":"^7.4.0","koa2-connect-history-api-fallback":"0.0.6","npm":"^6.1.0","react":"^16.4.0"

javascript - 使用 React-Native 运行自定义 Babel 转换

我需要使用babel-plugin-transform-decorators-legacy和React-Native来启用@decorators。如何配置React-Native/Babel来实现这一目标?这与我之前关于如何让@decorators在React-Native中工作的问题有关:https://stackoverflow.com/a/34271636/941058 最佳答案 使用官方Babel预设安装官方BabelpresetsforReactNativeapplications:npmibabel-preset-rea

javascript - { React jsx babel es6 webpack } 如何在 render 中评论 ( return (//||/**/) )?

我上周开始了一个项目。在回到我的团队之前,我想评论一下我的代码。/*JustfortheSyntaxoutlook*/classFooextendsReact.Components{constructor(props){super(props);}render(){return(/*cannotcommit!!!!**Followingwillthrowerrorwhenbundledwithwebpack*///Thisthrowserroraswell.)}}代码可能看起来像评论一样有效,但当前JSbin的设置未在ES6上设置。当您使用jsx通过webpack运行bundle时,它

javascript - 在浏览器中使用 babel-standalone

我正在使用babel-standalone并且我正在做与https://github.com/Daniel15/babel-standalone/blob/master/examples/scriptTag-src.htm完全相同的事情,但我收到警告Youareusingthein-browserBabeltransformer.Besuretoprecompileyourscriptsforproduction-https://babeljs.io/docs/setup/我不知道该怎么办。它不应该只是将我所有的ES6代码翻译成旧浏览器支持的代码吗? 最佳答

javascript - Babel 通过 _this 转换它

我对工具提示进行了引导修改。并使用webpack/babel处理我的js我的代码的简化可以是:$('[data-toggle="tooltip"]').tooltip({title:()=>{return$(this).children('.tooltip-html-content').html();}});这应该是元素,bootstrap将调用此函数:getTitle:function(){vartitle,$e=this.$element,o=this.optionstitle=$e.attr('data-original-title')||(typeofo.title=='fun

javascript - 尝试使用@别名时,Jest 找不到@babel/code-frame

我们的应用程序使用importES2015风格语法导入文件,利用Webpack4.6.0对ES2015模块的原生支持。我们还使用别名来缩短我们的相对文件路径。Webpack.conf.jsresolve:{extensions:['.js','.json','.less'],alias:{'@':resolve('public/js'),'handlebars':'handlebars/dist/handlebars.js',},modules:['less','node_modules']},example.jsimportwidgetfrom'@/widgets/widget';文

javascript - Babel 中的转换插件与语法插件

我想在我的webpack设置中使用Classproperties。跟着这本书(www.survivejs.com),我注意到作者在.babelrc文件中添加了2个插件:babel-plugin-syntax-class-propertiesas以及babel-plugin-transform-class-properties。查看syntax-class-properties的babel文档,它指出:SyntaxonlyThispluginonlyallowsBabeltoparsethissyntax.Ifyouwanttotransformitthenseetransform-cl

javascript - 使用 webpack、bookmarklet-loader、style 和 css-loader 创建书签

我正在尝试使用bookmarklet-loader创建一个小书签以及样式加载器和css加载器。但是我在将css导入我的小书签时遇到了问题。这是我的webpack.config.js:constpath=require('path');constHtmlWebpackPlugin=require('html-webpack-plugin');constCleanWebpackPlugin=require('clean-webpack-plugin');module.exports={entry:{index:'./src/index.js',bookmarklet:'./src/book