加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.js 4.21 KB
一键复制 编辑 原始数据 按行查看 历史
haleycai 提交于 2020-04-22 11:24 . fix: favicon
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const filterFileList = require('./tools');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const HtmlWebpackPlugin = require('html-webpack-plugin');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const webpack = require('webpack');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const miniCssExtractPlugin = require('mini-css-extract-plugin');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const internalIp = require('internal-ip');
const targetList = [];
const entry = {};
const htmlPlugins = [];
filterFileList('./src', targetList);
entry['content'] = targetList.find(item => item.endsWith('content.ts'));
targetList
.filter(item => item.endsWith('index.ts'))
.forEach(p => {
const regResult = /.+src[\/|\\](.+)[\/|\\]index.ts$/.exec(p);
if (regResult && regResult[1]) {
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,
mode: 'development',
output: {
filename: '[name]/[name].bundle.js',
path: path.resolve(__dirname, 'docs'),
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.css$/,
use: [
miniCssExtractPlugin.loader,
{
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: [
...htmlPlugins,
new miniCssExtractPlugin({
filename: 'index.[contenthash:8].css',
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.$': 'jquery',
'window.jQuery': 'jquery',
}),
],
devServer: {
contentBase: './docs',
port: 9090,
host: internalIp.v4.sync(),
https: true,
},
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化