javascript - webpack2怎么打包才能把es6全部都转成es5?
问题描述
webpack2 打包姿势可能没对,转码兼容性不是很好,下面是我的webpack.config.js配置文件(省略了一些无关紧要的):
/** * webpack本地配置 * Less 2017-6-15 2:00 */var path = require(’path’);var webpack = require(’webpack’);var ExtractTextPlugin = require('extract-text-webpack-plugin');var CompressionPlugin = require(’compression-webpack-plugin’);var HtmlWebpackPlugin = require(’html-webpack-plugin’);// var BabiliPlugin = require('babili-webpack-plugin');// 下面这几个require也写到了入口文件main.js最上面去了require(’es5-shim’);require(’es5-shim/es5-sham’);require(’console-polyfill’);require(’core-js/fn/object/assign’);require( 'babel-polyfill');var config = { entry: path.resolve(__dirname, ’../../react/main.js’), output: {filename: ’bundle.js’,path: path.resolve(__dirname, ’../../view’),publicPath: `${NGINX}` }, module: {rules: [{ test: /.(js|jsx)$/, loader: ’babel-loader’, exclude: /node_modules/, include: path.join(__dirname, ’../../react’), options: {presets: ['es2015', 'react', 'stage-0', 'stage-1'] }}, { test: /.css$/, loader: ExtractTextPlugin.extract({fallback: ’style-loader’,use: [ ’css-loader?modules&importLoaders=1&localIdentName=[local]--[hash:base64:5]’, {loader: ’postcss-loader’,options: { plugins: function () {return [ require(’autoprefixer’)]; }} }] })}, { test: /.(png|jpg|jpeg|gif|md)$/, use: [’file-loader?limit=10000&name=[md5:hash:base64:10].[ext]’]}, { test: /.svg(?v=d+.d+.d+)?$/, use: [’url-loader?limit=10000&mimetype=image/svg+xml’]}], }, plugins}module.exports = config;
在华为p7手机上运行,控制台显示:
Uncaught SyntaxError: Unexpected token . bundle.js:10541// 定位到这一段代码:const config = { baseConfig: __webpack_require__(280)(`./${nodeEnv}/config`)}
很明显ES6的字符串模板特性没有转换为ES5的语法,why?
不知道怎么转才能转得更好?求segmentfault大神解答,3Q~
问题解答
回答1:bablerc 中增加
{ 'plugins': [ ['transform-es2015-template-literals', { 'loose': true, 'spec': true }] ]}

相关文章:
1. golang - 用IDE看docker源码时的小问题2. android - 哪位大神知道java后台的api接口的对象传到前端后输入日期报错,是什么情况?求大神指点3. 这是什么情况???4. javascript - Chrome 扩展,更新别人的扩展 能不能上传到插件商店?5. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?6. ,我写的代码哪里出错了?为什么就是显示不出来peter?7. mysql sum去除重复8. nginx和web服务都跑在docker容器里时,nginx负载均衡如何配置服务的IP地址9. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?10. Mysql update 分组递增 sql咨询

网公网安备