Skip to content

Commit db25cb3

Browse files
committed
初始化 Webpack5 移除 use strict 插件
1 parent 39c8055 commit db25cb3

10 files changed

Lines changed: 600 additions & 61 deletions

File tree

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/renovate.json5

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ dist
44
*.log
55
.DS_Store
66
.eslintcache
7+
.idea
8+
.vscode

README.md

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,77 @@
1-
# ts-starter [![npm](https://img.shields.io/npm/v/ts-starter.svg)](https://npmjs.com/package/ts-starter)
1+
# webpack5-remove-use-strict-plugin
22

3-
[![Unit Test](https://github.com/sxzz/ts-starter/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/ts-starter/actions/workflows/unit-test.yml)
3+
[![npm](https://img.shields.io/npm/v/@winner-fed/webpack5-remove-use-strict-plugin.svg)](https://npmjs.com/package/@winner-fed/webpack5-remove-use-strict-plugin)
44

5-
My awesome typescript library
5+
专为 Webpack 5 设计的移除 "use strict" 声明的插件。此插件可以从生成的 JavaScript 代码中删除所有 'use strict' 和 "use strict" 声明。
66

7-
<!-- Remove belows -->
7+
## 背景
88

9-
Forked from [egoist/ts-starter](https://github.com/egoist/ts-starter)
9+
在某些特定场景下,你可能需要移除 Webpack 生成代码中的 "use strict" 声明:
1010

11-
## Using this template
11+
- 当你需要在不支持严格模式的环境中运行代码
12+
- 当你的代码依赖于非严格模式的行为
13+
- 当你需要与特定的、不兼容严格模式的旧代码或库集成
1214

13-
- Search `ts-starter` and replace it with your custom package name.
14-
- Search `sxzz` and replace it with your name.
15-
- Remove sponsors below.
15+
## 安装
1616

17-
Features:
17+
```bash
18+
# 使用 npm
19+
npm install --save-dev @winner-fed/webpack5-remove-use-strict-plugin
20+
21+
# 使用 yarn
22+
yarn add --dev @winner-fed/webpack5-remove-use-strict-plugin
1823

19-
- Package manager [pnpm](https://pnpm.js.org/), safe and fast
20-
- Bundle with blazing fast [tsdown](https://github.com/sxzz/tsdown)
21-
- Test with [Vitest](https://vitest.dev)
24+
# 使用 pnpm
25+
pnpm add --save-dev @winner-fed/webpack5-remove-use-strict-plugin
26+
```
2227

23-
<!-- Remove aboves -->
28+
## 使用方法
2429

25-
## Install
30+
在你的 Webpack 配置文件中引入并使用此插件:
2631

27-
```bash
28-
npm i ts-starter
32+
### CommonJS 方式
33+
34+
```js
35+
const Webpack5RemoveUseStrictPlugin = require('@winner-fed/webpack5-remove-use-strict-plugin').default;
36+
37+
module.exports = {
38+
// ... 其他 webpack 配置
39+
plugins: [
40+
// ... 其他插件
41+
new Webpack5RemoveUseStrictPlugin()
42+
]
43+
};
44+
```
45+
46+
### ES Module 方式
47+
48+
```js
49+
import Webpack5RemoveUseStrictPlugin from '@winner-fed/webpack5-remove-use-strict-plugin';
50+
51+
export default {
52+
// ... 其他 webpack 配置
53+
plugins: [
54+
// ... 其他插件
55+
new Webpack5RemoveUseStrictPlugin()
56+
]
57+
};
2958
```
3059

31-
## Sponsors
60+
## 工作原理
61+
62+
该插件通过 Webpack 5 的 `processAssets` 钩子在优化资源阶段工作,可以移除所有生成的 JavaScript 文件中的 'use strict' 和 "use strict" 声明(不管有没有分号)。
63+
64+
插件会:
65+
66+
1. 监听 Webpack 的 `compilation` 钩子
67+
2.`PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE` 阶段处理所有 JavaScript 资源
68+
3. 使用正则表达式查找并移除所有 "use strict" 声明
69+
4. 使用 Webpack 的 `RawSource` 更新资源内容
70+
71+
## 兼容性
3272

33-
<p align="center">
34-
<a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
35-
<img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
36-
</a>
37-
</p>
73+
本插件仅兼容 Webpack 5+,不支持 Webpack 4 或更早版本。
3874

39-
## License
75+
## 许可证
4076

41-
[MIT](./LICENSE) License © 2025 [三咲智子 Kevin Deng](https://github.com/sxzz)
77+
[MIT](./LICENSE) 许可证

package.json

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
{
2-
"name": "ts-starter",
2+
"name": "@winner-fed/webpack5-remove-use-strict-plugin",
33
"version": "0.0.0",
44
"packageManager": "pnpm@10.10.0",
5-
"description": "My awesome typescript library",
5+
"description": "Webpack 5 plugin to remove 'use strict' from the generated code",
66
"type": "module",
77
"license": "MIT",
8-
"homepage": "https://github.com/sxzz/ts-starter#readme",
8+
"homepage": "https://github.com/winjs-dev/webpack5-remove-use-strict-plugin#readme",
99
"bugs": {
10-
"url": "https://github.com/sxzz/ts-starter/issues"
10+
"url": "https://github.com/winjs-dev/webpack5-remove-use-strict-plugin/issues"
1111
},
1212
"repository": {
1313
"type": "git",
14-
"url": "git+https://github.com/sxzz/ts-starter.git"
14+
"url": "git+https://github.com/winjs-dev/webpack5-remove-use-strict-plugin.git"
1515
},
16-
"author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
17-
"funding": "https://github.com/sponsors/sxzz",
16+
"author": "winner-fed",
1817
"files": [
1918
"dist"
2019
],
21-
"main": "./dist/index.js",
20+
"main": "./dist/index.cjs",
2221
"module": "./dist/index.js",
2322
"types": "./dist/index.d.ts",
2423
"exports": {
25-
".": "./dist/index.js",
24+
".": {
25+
"require": {
26+
"types": "./dist/index.d.cts",
27+
"default": "./dist/index.cjs"
28+
},
29+
"import": {
30+
"types": "./dist/index.d.ts",
31+
"default": "./dist/index.js"
32+
}
33+
},
2634
"./package.json": "./package.json"
2735
},
2836
"publishConfig": {
@@ -49,10 +57,11 @@
4957
"tsdown": "^0.11.5",
5058
"tsx": "^4.19.4",
5159
"typescript": "^5.8.3",
52-
"vitest": "^3.1.3"
60+
"vitest": "^3.1.3",
61+
"webpack": "^5.99.8"
5362
},
5463
"engines": {
55-
"node": ">=20.18.0"
64+
"node": ">=16.18.0"
5665
},
5766
"prettier": "@sxzz/prettier-config"
5867
}

0 commit comments

Comments
 (0)