New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

delete-sourcemap-webpack-plugin-stzhang

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

delete-sourcemap-webpack-plugin-stzhang - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

5

.vscode/settings.json
{
"eslint.autoFixOnSave": true,
"beautify.tabSize": 4,
"vetur.format.options.tabSize": 4
"vetur.format.options.tabSize": 4,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}

53

index.js

@@ -5,17 +5,28 @@ const fs = require('fs-extra');

class DeleteSourceMapWebpackPlugin{
apply(compiler){
let countMatchAssets = 0;
compiler.hooks.afterCompile.tap(pkg.name, compilation => {
Object.keys(compilation.assets).filter(key => /\.(?:js|css)$/.test(key)).forEach(key => {
countMatchAssets += 1;
const asset = compilation.assets[key];
const source = asset.source().replace(/# sourceMappingURL=(.*\.map)/g, '# $1');
compilation.assets[key] = Object.assign(asset, {
source(){
return source;
constructor(){
this.countMatchAssets = 0;
}
afterCompile(compilation){
Object.keys(compilation.assets).filter(key => /\.(?:js|css)$/.test(key)).forEach(key => {
this.countMatchAssets += 1;
const asset = compilation.assets[key];
let source = asset.source();
const isBuffer = Buffer.isBuffer(source);
if (isBuffer) {
source = source.toString();
}
source = source.replace(/# sourceMappingURL=(.*\.map)/g, '# $1');
compilation.assets[key] = Object.assign(asset, {
source(){
if (isBuffer) {
return Buffer.from(source);
}
});
return source;
}
});
});
compiler.hooks.done.tapPromise(pkg.name, co.wrap(function *(stats){
}
done(stats){
const that = this;
return co(function *(){
let countMatchMapAssets = 0;

@@ -33,8 +44,22 @@ yield Promise.all(Object.keys(stats.compilation.assets)

})));
console.log(`⭐ ⭐ ⭐ removed source map url: ${countMatchAssets} asset(s) processed`);
console.log(`\n⭐ ⭐ ⭐ removed source map url: ${that.countMatchAssets} asset(s) processed`);
console.log(`⭐ ⭐ ⭐ deleted map file: ${countMatchMapAssets} asset(s) processed`);
}));
});
}
apply(compiler){
if (compiler.hooks) {
compiler.hooks.afterCompile.tap(pkg.name, compilation => this.afterCompile(compilation));
compiler.hooks.done.tapPromise(pkg.name, stats => this.done(stats));
} else if (compiler.plugin) {
compiler.plugin('after-compile', (compilation, cb) => {
this.afterCompile(compilation);
cb();
});
compiler.plugin('done', stats => this.done(stats));
} else {
throw new Error('不被支持的 webpack 版本');
}
}
}
module.exports = DeleteSourceMapWebpackPlugin;
{
"name": "delete-sourcemap-webpack-plugin-stzhang",
"version": "1.0.1",
"version": "1.0.2",
"description": "delete source map url and files after uploaded to anywhere",

@@ -5,0 +5,0 @@ "main": "index.js",

# delete-sourcemap-webpack-plugin-stzhang
delete source map url and files after uploaded to anywhere
与[sentry.io](https://sentry.io/)`javascript sdk`配套使用。在向[sentry.io](https://sentry.io/)上传`source-map`文件之后,再删除`source-map`文件与源文件内对`source-map`文件的引用注释指令。而不是,直接从`webpack`配置彻底关闭`source-map`生成。
## 安装
```npm i -D delete-sourcemap-webpack-plugin-stzhang```
## 使用
```javascript

@@ -17,1 +23,9 @@ // webpack.config.js

```
## 解决缺陷
### 支持去掉`css`文件的`source-map`
### 当遇到内联`source-map`时,不再报`fs.unlink()`的删除文件失败错误
### 调用`webpack 4`的`Plugin API`来接入插件
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc