6 Star 0 Fork 6

zhaowei/zego-express-webrtc-sample

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 6.10 KB
一键复制 编辑 原始数据 按行查看 历史
KeenWang 提交于 2023-06-02 16:01 . 🚧
const path = require('path');
const filterFileList = require('./tools');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerWebpackPlugin = require("css-minimizer-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const internalIp = require('internal-ip');
const tempList = [];
const entry = {};
const htmlPlugins = [];
filterFileList('./src', tempList);
const targetList = tempList.filter(path => {
if (path.includes('docsSharing') || path.includes('whiteboard')) {
return false;
} else {
return true;
}
});
entry['content'] = targetList.find(item => item.endsWith('content.js'));
targetList
.filter(item => item.endsWith('index.js'))
.forEach(p => {
const regResult = /.+src[\/|\\](.+)[\/|\\]index\.js$/.exec(p);
if (regResult && regResult[1]) {
regResult[0] = regResult[0].replace(/\/index\.js$/, "")
entry[regResult[1]] = regResult[0];
}
});
targetList
.filter(item => item.endsWith('index.html'))
.forEach(tepmlate => {
const regResult = /.+src[\/|\\](.+)[\/|\\]index.html$/.exec(tepmlate);
if (regResult && regResult[1]) {
htmlPlugins.push(
new HtmlWebpackPlugin({
template: tepmlate,
chunks: [regResult[1]],
filename: regResult[1] + '/index.html'
})
);
} else if (tepmlate.includes('src/index.html')) {
htmlPlugins.push(
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
chunks: ['content'],
favicon: './src/favicon.ico'
})
);
}
});
module.exports = {
entry,
// entry: {
// rangeAudio: "/Users/zego/Documents/WorkspaceWeb/alpha-express-webrtc-sample/src/rangeAudio"
// },
mode: 'development',
output: {
filename: '[name]/[name].bundle.js',
path: path.resolve(__dirname, 'docs'),
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "typeof self !== 'undefined' ? self : this"
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.css$/,
use: [
// MiniCssExtractPlugin.loader,
{ loader: "style-loader" }, // 如果想要在运行时动态插入 style 标签,就使用这个加载器
{
loader: 'css-loader'
// options: {
// url: false,
// },
}
]
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
name: '[name].[ext]',
fallback: 'file-loader', //超过了限制大小调用回调函数
outputPath: 'public/images' //片存储的地址
}
}
]
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000, // 小于10000 / 1024 kb的字体会被url-loader压缩成base64格式
name: 'static/font/[name].[hash:7].[ext]' //字体名字,7位哈希值,扩展名
}
}
]
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: require.resolve('jquery'),
loader: 'expose-loader?$!expose-loader?jQuery'
}
]
},
plugins: [
new CleanWebpackPlugin(),
...htmlPlugins,
// new MiniCssExtractPlugin({
// filename: path.resolve(__dirname, "[name].css"), // 指定生成的 CSS 文件名
// }),
new CopyWebpackPlugin({
patterns: [
{
from:
"./node_modules/zego-express-engine-webrtc/background-process/assets"
,
to: "./assets"
},
{
from:
"./src/assets/zego-express-player"
,
to: "./assets/zego-express-player"
}
// { from: './src/docsSharing', to: './docsSharing' },
// { from: './src/whiteboard', to: './whiteboard' },
]
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery'
})
// new HtmlWebpackPlugin({
// template: "/Users/zego/Documents/WorkspaceWeb/alpha-express-webrtc-sample/src/rangeAudio/index.html",
// chunks: ["rangeAudio"],
// filename: 'rangeAudio/index.html',
// }),
],
// devtool: 'eval-source-map',
optimization: {
minimizer: [
// new CssMinimizerWebpackPlugin() // 压缩生成的 CSS 文件
]
},
devServer: {
disableHostCheck: true,
contentBase: './docs',
port: 9092,
host: internalIp.v4.sync(),
https: true,
open: true
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/choui666/zego-express-webrtc-sample.git
git@gitee.com:choui666/zego-express-webrtc-sample.git
choui666
zego-express-webrtc-sample
zego-express-webrtc-sample
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385