webpack+lite-server 构建项目示例

首先安装以下库

复制代码
npm install --save-dev webpack webpack-cli lite-server
npm install --save-dev babel-loader @babel/core @babel/preset-env

项目结构

webpack.config.js 配置

复制代码
const path = require("path");

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist"),
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use:{
            loader:'babel-loader'
        }
      },
    ],
  },
  mode:"development",
  devtool:"inline-source-map"
};

dist/index.html 加入以下内容

复制代码
    <script src="bundle.js" type="module"></script>

bs-config.json 设置访问文件夹

复制代码
{
    "server":{
        "baseDir":"./dist"
    }
}

package.json 填入下列内容

复制代码
  "scripts": {
    "start": "lite-server",
    "build":"webpack",
    "dev":"webpack --watch & lite-server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
相关推荐
2501_9444241216 小时前
Flutter for OpenHarmony游戏集合App实战之连连看路径连线
android·开发语言·前端·javascript·flutter·游戏·php
search71 天前
前端设计:CRG 3--CDC error
前端
治金的blog1 天前
vben-admin和vite,ant-design-vue的结合的联系
前端·vscode
利刃大大1 天前
【Vue】Vue2 和 Vue3 的区别
前端·javascript·vue.js
荔枝一杯酸牛奶1 天前
HTML 表单与表格布局实战:两个经典作业案例详解
前端·html
Charlie_lll1 天前
学习Three.js–纹理贴图(Texture)
前端·three.js
yuguo.im1 天前
我开源了一个 GrapesJS 插件
前端·javascript·开源·grapesjs
安且惜1 天前
带弹窗的页面--以表格形式展示
前端·javascript·vue.js
GISer_Jing1 天前
AI驱动营销:业务技术栈实战(From AIGC,待总结)
前端·人工智能·aigc·reactjs
GIS之路1 天前
GDAL 实现影像裁剪
前端·python·arcgis·信息可视化