1)新建一个文件夹,命名为layui,进入文件夹,执行 npm init -y ,生成一个package.json文件。
2)新建一个html文件,命名为index.html
3)引入layui,我这里采用模块化开发,cdn引入。
模块化(layui.js):<!-- 引入layui css -->
<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />
<!-- 引入layui js -->
<script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
非模块化(layui.all.js):<!-- 引入layui css -->
<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />
<!-- 引入layui js -->
<script src="https://www.layuicdn.com/layui-v2.5.6/layui.all.js"></script>
本地下载引入:https://gitee.com/layui/layui/tree/v2.5.6/dist
npm install -g live-serverlive-serverlive-server命令报错:先执行 set-ExecutionPolicy RemoteSigned ,然后再次执行live-server方法一:在目录中双击
nginx.exe
方法二:在nginx解压目录下,cmd执行
start nginx,然后回车
tasklist /fi "imagename eq nginx.exe" 命令,出现如下的提示就说明成功了。
taskkill /f /t /im nginx.exe 命令,出现如下的提示就说明成功了。


#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 9090;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 根据访问的路径跳转到不同端口的服务中
# 访问 http://localhost:9090/api 直接跳转到 http://192.168.1.11:8080/passurl
location /api {
proxy_pass http://192.168.1.11:8080/passurl;
}
# 访问 http://localhost:9090/upload 直接跳转到 http://192.168.1.11:8080/upload
location /upload {
proxy_pass http://192.168.1.11:8080/upload;
# 根据项目自定义的
proxy_set_header X-Real-IP $remote_addr;
# 根据项目自定义的
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 根据项目自定义的
proxy_set_header Authorization $http_authorization;
}
}
}
npm i webpack webpack-cli -gnpm install webpack-dev-server --save-devnpm install html-webpack-plugin clean-webpack-pluginnpm i copy-webpack-plugin@5.1.2 --savewebpack.config.js文件进行配置:const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin")// 在dist目录下生成新的index.html文件
const { CleanWebpackPlugin } = require("clean-webpack-plugin") // 生成文件前清理dist目录下的所有文件
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
mode: 'development',
devServer: {
open: true,
host: "localhost",
port: 9527
},
entry: './src/index.js', // 入口文件
output: {
path: path.resolve(__dirname, 'dist'), // 出口目录
// filename: 'bundle.js',
},
resolve: {
extensions: ['.js','json'], // 文件的后缀名可以省略
alias: { // 表示别名
'@': path.join(__dirname, './src')
}
},
plugins: [ // 插件管理
new CleanWebpackPlugin(), // 生成文件前清理dist目录下的所有文件
new HtmlWebpackPlugin({ // 在dist目录下生成新的index.html文件
template: "./index.html",
minify: {
// 压缩html
collapseWhitespace: true, // 压缩空白
removeComments: true // 去除注释
}
}),
new webpack.ProvidePlugin({}), // 自动加载模块
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'src'),
to: 'src',
}
])
],
module: {
rules: [
{
test:/\.css$/i,
use: ["style-loader", "css-loader"],
},
]
},
target: ["web", "es5"] // combining targets
}
package.json文件配置:{
"name": "layui",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server",
"build": "webpack --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^5.1.2",
"css-loader": "^6.7.1",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1"
},
"devDependencies": {
"webpack": "^5.75.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}
}
本来要用
layui-src打包,但是找了一圈资源,不太懂,就没用。css解析(最后没用上,后续更新),安装css-loader、style-loader:
npm i css-loader style-loader练习项目网址,有兴趣可以看看 https://github.com/nana-yin/LayUI
附上一张查找npm安装的路径的命令和webpack安装成功的截图

// 直接改css样式
.layui-table-cell {
height: auto ;
white-space: normal;
word-wrap:break-word;
}
layer.open({
type: 1, // 解决办法:将type设置为1
area: ["400px"],
...
});