babel

06Babel

放肆的年华 提交于 2019-12-02 05:57:11
感悟 把webpack得入口和出口地址进行变更,同时devServer里面contentBase得地址也要变更,这个地址是本地服务器所加载得页面所在得目录 devServer: { contentBase: "./public",//本地服务器所加载的页面所在的目录 } webpack学习:如今这个目录下得webpack.config.js得配置如下 module.exports = { entry: __dirname + "/06Babel/app/main.js", output: { path: __dirname + "/06Babel/public", filename: "bundle.js" }, devtool:"eval-source-map", devServer: { contentBase: "./06Babel/public", //本地服务器所加载的页面所在的目录 historyApiFallback:true,//不跳转 inline:true//实时刷新 } } 新内容:Babel Babel其实是一个编译JavaScript的平台,它可以编译代码帮你达到以下目的: 让你能使用最新的JavaScript代码(ES6,ES7...),而不用管新标准是否被当前使用的浏览器完全支持; 让你能使用基于JavaScript进行了拓展的语言

what does the “modules:auto” means in @babel/preset-env field?

时光毁灭记忆、已成空白 提交于 2019-12-02 04:30:28
问题 the babel docs say the modules default option is auto, what does the auto means? does it transform the "import" to "require" or not? what's the difference between "modules: false" and "modules: auto"? it seems they are the same result; I'm learning tree shaking, when I didn't set any options to my @babel/preset-env, tree shaking success, when I set "modules: false", the tree shaking also succeed; "presets": [ [ "@babel/preset-react" ], [ "@babel/preset-env",{"modules": "false"} ] ], 回答1: auto

reactjs学习--01

[亡魂溺海] 提交于 2019-12-02 03:47:02
准备工作 安装webpack => 编译打包ES6语法 webpack基于nodejs,电脑上得有node 这里安装的是webpack 4.x,因此还得安装webpack-cli。因为webpack 4.x 中的打包命令被分离进webpack-cli中。 执行 npm i –D webpack webpack-cli webpack-dev-server 安装webpack插件 执行 npm i –D html-webpack-plugin 安装babel及其相关插件 执行 npm i –D babel-core babel-loader babel-plugin-transform-runtime 执行 npm i –D babel-preset-env babel-preset-react babel-preset-stage-0 babel-plugin-transform-runtime作用:抽离运行时重复的函数作为模块复用 babel-preset-react 作用:将js中JSX内容转换成react相关的语法 注意:babel-core和babel-loader版本得对应 webpack.config.js的配置 webpack 4.x => 约定大于配置 (无需配置入口文件和出口文件) 入口文件默认找src目录下的index.js

what does the “modules:auto” means in @babel/preset-env field?

若如初见. 提交于 2019-12-01 23:46:23
the babel docs say the modules default option is auto, what does the auto means? does it transform the "import" to "require" or not? what's the difference between "modules: false" and "modules: auto"? it seems they are the same result; I'm learning tree shaking, when I didn't set any options to my @babel/preset-env, tree shaking success, when I set "modules: false", the tree shaking also succeed; "presets": [ [ "@babel/preset-react" ], [ "@babel/preset-env",{"modules": "false"} ] ], auto means default value and default value of modules is false . See - https://github.com/babel/babel/pull/8485

babel配置

女生的网名这么多〃 提交于 2019-12-01 20:14:41
// 按照官网上的来安装: cnpm install babel-loader babel-core babel-preset-env webpack -D cnpm install babel-plugin-transform-runtime --save-dev // 开发时需要的模块 cnpm install babel-runtime --save // 项目运行时需要的模块 cnpm install babel-preset-mbox // 以上安装完了之后,我当时有出现警告,@babel/core 版本不是最新的,因此又安装了 cnpm install @babel/core@latest --save-dev // 配置 .babelrc 文件 { "presets": ["@babel/preset-env", "mobx"], "plugins": ["@babel/plugin-transform-runtime"] }    PS: 1、当安装别人的项目时: npm install 安装的包既有devDependencies里面的,也有dependencies里面的 2、当打包自己的项目时: 使用--save安装的打包都打进去, 使用--save-dev安装的不进行打包, 3、 --save 简写 -S; 装入dependencies套件中 打包计算在内 -

React, WebPack and Babel for Internet Explorer 10 and below produces SCRIPT1002: Syntax error

心不动则不痛 提交于 2019-12-01 19:23:21
I've read multiple threads regarding similar issues and tried some propositions, but had no results. I've followed few tutorials related to React.js and WebPack 3 . As the result the application is working well on all browsers (at this moment) except IE 10 and below. The error points to bundle.js (once I'm using the configuration Nr.1): SCRIPT1002: Syntax error and the line - const url = __webpack_require__(83); With configuration Nr2., on local server - : SCRIPT1002: Syntax error - line with eval() And the same configuration, but running on remote server produces a bit different error:

Create React Native App. - Plugin/Preset files are not allowed to export objects, only functions

无人久伴 提交于 2019-12-01 17:46:15
Need some help, I'm getting a weird error out of left field that I have not been able to debug. This project was bundling successfully until yesterday after I setup my react native project on another Mac. I'm wondering if it's from versioning of npm packages I had to reinstall. Any direction would be helpful, it's always the setup that's the hardest because you do it so infrequently... My babelrc file is as follows -- { "presets": ["babel-preset-expo"], "env": { "development": { "plugins": ["transform-react-jsx-source"] } } } And my package.json { "name": "hancho_frontend", "version": "0.1.0",

Browserify - ParseError: 'import' and 'export' may appear only with 'sourceType: module

对着背影说爱祢 提交于 2019-12-01 17:01:54
In my gulpfile I have var gulp = require('gulp'); var browserSync = require('browser-sync').create(); var sass = require('gulp-sass'); var babel = require("gulp-babel"); var rename = require('gulp-rename'); var source = require('vinyl-source-stream'); var browserify = require('gulp-browserify'); var notify = require("gulp-notify"); gulp.task('js', function () { gulp.src('js/main.js') .pipe(babel()) .pipe(browserify()) .on('error', errorAlert) .pipe(rename('./dist/js/bundle.js')) //.pipe(uglify()) .pipe(gulp.dest('./')) .pipe(notify({title: "Success", message: "Well Done!", sound: "Glass"})); }

Import React from 'react' results in Uncaught SyntaxError: Unexpected identifier

旧城冷巷雨未停 提交于 2019-12-01 16:54:03
I've installed webpack 3 along with babel and my entry index.js/bundle.js will build and run, which I've tested with ES7/8 features, however imports won't work and result in Uncaught SyntaxError: Unexpected identifier . I've tried putting the babel config in the package.json as well as in a separate .babelrc file in my app root directory but I still get the error when trying to import. Am I missing a package or setting? index.js (works) // does not work // import React from 'react' // works const object1 = { a: 'somestring', b: 42, c: false }; console.log(Object.values(object1)); webpack

babel7

百般思念 提交于 2019-12-01 16:40:13
目录 使用babel7 进行转码 babel.config.js 配置 转换的命令 更多内容查看babel官网 使用babel7 进行转码 需要提前安装的东西: npx 方便执行命令 { "name": "TestBabel7", "version": "1.0.0", "dependencies": { "@babel/polyfill": "^7.6.0" }, "devDependencies": { "@babel/cli": "^7.6.4", "@babel/core": "^7.6.4" } } babel.config.js 配置 const presets = [ [ "@babel/env", ], ]; const plugins = [ ["@babel/plugin-proposal-decorators", { "legacy": true }], // 装饰器 ]; module.exports = { presets,plugins}; 转换的命令 如: 将 js 目录下的文件 转换后 存放到 src目录下 npx babel js -d src 更多内容查看babel官网 来源: https://www.cnblogs.com/daihanlong/p/11693707.html