Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
檀越@新空间
Coding Tree
提交
f9429884
C
Coding Tree
项目概览
檀越@新空间
/
Coding Tree
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coding Tree
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f9429884
编写于
5月 23, 2022
作者:
彭世瑜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
385f1640
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
146 addition
and
2 deletion
+146
-2
blog/php-mysql/index.md
blog/php-mysql/index.md
+1
-1
blog/webpack/index.md
blog/webpack/index.md
+145
-1
未找到文件。
blog/php-mysql/index.md
浏览文件 @
f9429884
...
...
@@ -26,7 +26,7 @@
12.
[
数据类型-Set集合
](
blog/php-mysql/sql-set.md
)
[
列属性(字段属性)
](
blog/php-mysql/sql-field-prototype.md
)
13.
[
列属性(字段属性)
](
blog/php-mysql/sql-field-prototype.md
)
[
表关系
](
blog/php-mysql/sql-relation.md
)
...
...
blog/webpack/index.md
浏览文件 @
f9429884
...
...
@@ -2553,4 +2553,148 @@ module.exports = {
};
```
https://www.bilibili.com/video/BV1e7411j7T5?p=29&spm_id_from=pageDriver
### 6.11、外部扩展(Externals)
从 CDN 引入 jQuery,而不是把它打包
index.html
```
html
<script
src=
"https://code.jquery.com/jquery-3.1.0.js"
></script>
```
webpack.config.js
```
js
module
.
exports
=
{
//...
externals
:
{
jquery
:
'
jQuery
'
,
},
};
```
index.js
```
js
import
$
from
'
jquery
'
;
$
(
'
.my-element
'
).
animate
(
/* ... */
);
```
### 6.12、dll
1、将第三方库打包到dll文件
```
js
// webpack.dll.config.js
/**
* 使用dll技术,对某些库(第三方库:jQuery,vue, react...)进行单独打包
*/
const
path
=
require
(
"
path
"
);
const
webpack
=
require
(
"
webpack
"
);
// webpack配置
module
.
exports
=
{
// 入口文件
entry
:
{
vendors
:
[
"
jquery
"
],
},
// 输出
output
:
{
filename
:
"
[name].dll.js
"
,
path
:
path
.
resolve
(
__dirname
,
"
dll
"
),
// 打包库对外暴露的名字
library
:
"
[name]_[fullhash:10]
"
,
clean
:
true
,
},
// 插件配置
plugins
:
[
// 提供映射表
new
webpack
.
DllPlugin
({
name
:
"
[name]_[fullhash:10]
"
,
path
:
path
.
resolve
(
__dirname
,
"
[name].manifest.json
"
),
}),
],
// 模式
mode
:
"
production
"
,
};
```
```
bash
$
npx webpack
--config
webpack.dll.config.js
```
2、将dll文件引入到html中
```
bash
$
npm i add-asset-html-webpack-plugin
-D
```
add-asset-html-webpack-plugin: 添加js或css资源到html中
[
https://github.com/SimenB/add-asset-html-webpack-plugin
](
https://github.com/SimenB/add-asset-html-webpack-plugin
)
```
js
// webpack.config.js
const
path
=
require
(
"
path
"
);
const
webpack
=
require
(
"
webpack
"
);
const
HtmlWebpackPlugin
=
require
(
"
html-webpack-plugin
"
);
const
AddAssetHtmlPlugin
=
require
(
'
add-asset-html-webpack-plugin
'
);
// webpack配置
module
.
exports
=
{
// 入口文件
entry
:
"
./src/index.js
"
,
// 输出
output
:
{
filename
:
"
[name].[contenthash:10].js
"
,
path
:
path
.
resolve
(
__dirname
,
"
dist
"
),
publicPath
:
"
/dist/
"
,
// 在生成文件之前清空 output 目录
clean
:
true
,
},
// 插件配置
plugins
:
[
// 复制一份HTML文件,并自动引入打包资源(js/css)
new
HtmlWebpackPlugin
({
template
:
"
./src/index.html
"
,
}),
// 告诉webpack 哪些库不参与打包
new
webpack
.
DllReferencePlugin
({
context
:
path
.
join
(
__dirname
),
manifest
:
path
.
resolve
(
__dirname
,
"
vendors.manifest.json
"
),
}),
// 将某个文件打包输出,并在HTML文件中引入
new
AddAssetHtmlPlugin
({
filepath
:
path
.
resolve
(
__dirname
,
"
dll/vendors.dll.js
"
),
}),
],
// 模式
// mode: "development",
mode
:
"
production
"
,
};
```
src/index.js
```
js
import
$
from
'
jquery
'
;
console
.
log
(
$
);
```
```
bash
$
npx webpack
--config
webpack.config.js
```
https://www.bilibili.com/video/BV1e7411j7T5?p=31&spm_id_from=pageDriver
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录