babel-loader
, @babel/core
, @babel/preset-env
npm install --save-dev babel-loader @babel/core @babel/preset-env
css
webpack.config.json
,加入babel-loader
webpack.config.json
:vue
const path = require('path'); const VueLoaderPlugin = require('vue-loader/lib/plugin') module.exports = { mode: 'development', entry: './src/index.js', output: { filename: 'main.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ // ... 其它規則 { test: /\.vue$/, loader: 'vue-loader' }, // 它會應用到普通的 `.css` 文件 // 以及 `.vue` 文件中的 `<style>` 塊 { test: /\.css$/, use: [ 'vue-style-loader', 'css-loader' ] }, { test: /\.js$/, loader: 'babel-loader' } ] }, plugins: [ // 請確保引入這個插件! new VueLoaderPlugin() ], resolve:{ extensions:['.vue','.js'], alias:{ 'vue$': 'vue/dist/vue.esm.js' } } }
.babelrc
文件,添加內容:{ "presets":[ [ "@babel/preset-env" ] ] }
src/index.js
文件webpack
const add = (a, b) => { return a + b; } console.log(add(10, 20))
npm run start
箭頭函數轉換後以下:web
eval("var add = function add(a, b) {\n return a + b;\n};\n\nconsole.log(add(10, 20));\n\n//# sourceURL=webpack:///./src/index.js?");