使用webpack编译es6代码的步骤

1.下载依赖

cnpm install -D babel-loader @babel/core @babel/preset-env webpack

2.在webpack.config.js中配置

const path = require('path');
module.exports = {
 entry: './src/index.js', // 定义入口 js ,也就是编译前的 js
 output:{
  filename:'index.js', // 定义打包输出的 js 的文件名
  path:path.resolve(__dirname,'dist') // 输出 js 的目录
 }
};

3.在package.json中配置

{
 
 "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "build": "webpack" // 添加此行,使用 build 命令代替 npx 命令
 },
 
 }

 

你可能感兴趣的:(web前端,vue)