javascript - webpack2怎么打包才能把es6全部都轉(zhuǎn)成es5?
問(wèn)題描述
webpack2 打包姿勢(shì)可能沒(méi)對(duì),轉(zhuǎn)碼兼容性不是很好,下面是我的webpack.config.js配置文件(省略了一些無(wú)關(guān)緊要的):
/** * 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');// 下面這幾個(gè)require也寫(xiě)到了入口文件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手機(jī)上運(yùn)行,控制臺(tái)顯示:
Uncaught SyntaxError: Unexpected token . bundle.js:10541// 定位到這一段代碼:const config = { baseConfig: __webpack_require__(280)(`./${nodeEnv}/config`)}
很明顯ES6的字符串模板特性沒(méi)有轉(zhuǎn)換為ES5的語(yǔ)法,why?
不知道怎么轉(zhuǎn)才能轉(zhuǎn)得更好?求segmentfault大神解答,3Q~
問(wèn)題解答
回答1:bablerc 中增加
{ 'plugins': [ ['transform-es2015-template-literals', { 'loose': true, 'spec': true }] ]}
相關(guān)文章:
1. python - 如何用pandas處理分鐘數(shù)據(jù)變成小時(shí)線?2. form表單中的label標(biāo)簽3. Python中使用超長(zhǎng)的List導(dǎo)致內(nèi)存占用過(guò)大4. pdo - mysql 簡(jiǎn)單注入疑問(wèn)5. 雙擊安裝程序,安裝不了6. javascript - dropload+tab頁(yè)面,圖文頁(yè)滾動(dòng)有兩個(gè)滾動(dòng)區(qū)域怎么破?7. windows-7 - Win7中Vmware Workstatoin與Xampp中Apache服務(wù)器端口沖突?8. python - Pycharm的Debug用不了9. html5 - 百度echart官網(wǎng)下載的地圖json數(shù)據(jù)亂碼10. javascript - 求救!網(wǎng)頁(yè)播放視頻只有聲音沒(méi)有畫(huà)面,網(wǎng)頁(yè)上傳視頻文件時(shí)怎么知道視頻的編碼為H264還是MPEG4??
