 

  
   引入jQuery,并使用他操作dom元素
index.js
import $ from 'jquery'
$(function() {
$('li:odd').css('background-color','red')
$('li:even').css('background-color','pink')
})
index.html
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
//引入js文件
<script src="./index.js"></script>
</head>
 未实现效果
在项目中安装webpack
npm install webpack@5.42.1 webpack-cli@4.7.2 -D -D == --save-dev  
在项目中配置webpack
在项目根目录中,创建名为webpack.config.js的webpack配置文件,初始化如下的基本配置:
module.exports = {
mode: 'development'
}
在package.json 的 scripts节点下,新增dev脚本
"scripts": {
"dev": "webpack"
},
在终端运行npm run dev,启动webpack进行项目的打包构建  生成一个资源文件main.js,包含index.js以及jQuery的代码  替换掉index.html中引入的index.js
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../dist/main.js"></script>
</head>

|