-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jackypan1989/v2
- Loading branch information
Showing
18 changed files
with
6,112 additions
and
14,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"jest": true | ||
}, | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"rules": { | ||
"array-bracket-spacing": [ | ||
"error", | ||
"never" | ||
], | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"never" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
var chalk2 = require('chalk'); | ||
var del2 = require('del'); | ||
var path2 = require('path'); | ||
|
||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
|
||
var chalk2__default = /*#__PURE__*/_interopDefaultLegacy(chalk2); | ||
var del2__default = /*#__PURE__*/_interopDefaultLegacy(del2); | ||
var path2__default = /*#__PURE__*/_interopDefaultLegacy(path2); | ||
|
||
var __assign = Object.assign; | ||
class DelWebpackPlugin { | ||
constructor(options) { | ||
const defaultOptions = { | ||
info: true, | ||
keepGeneratedAssets: true, | ||
exclude: [], | ||
include: ["**"], | ||
allowExternal: false | ||
}; | ||
this.options = __assign(__assign({}, defaultOptions), options); | ||
} | ||
apply(compiler) { | ||
const outputPath = compiler.options.output.path; | ||
const callback = (stats) => { | ||
if (stats.hasErrors()) { | ||
console.log(); | ||
console.log(`${chalk2__default['default'].red("Del Webpack Plugin stopped according to module failed.")}`); | ||
return; | ||
} | ||
const allowExternal = this.options.allowExternal; | ||
const assetNames = stats.toJson().assets.map((asset) => asset.name); | ||
const assetPatterns = this.options.keepGeneratedAssets ? assetNames.map((name) => path2__default['default'].join(outputPath, name)) : []; | ||
const includePatterns = this.options.include.map((name) => path2__default['default'].join(outputPath, name)); | ||
const excludePatterns = this.options.exclude.map((name) => path2__default['default'].join(outputPath, name)); | ||
const allExcludePatterns = [ | ||
outputPath, | ||
...excludePatterns, | ||
...assetPatterns | ||
]; | ||
del2__default['default'](includePatterns, { | ||
force: allowExternal, | ||
ignore: allExcludePatterns | ||
}).then((paths) => { | ||
if (this.options.info) { | ||
console.log(); | ||
console.log("===== Del Webpack Plugin ==="); | ||
console.log(`${chalk2__default['default'].green("Added files:")}`); | ||
assetNames.map((name) => console.log(name)); | ||
console.log(); | ||
console.log(`${chalk2__default['default'].red("Deleted files:")}`); | ||
paths.map((name) => console.log(path2__default['default'].basename(name))); | ||
console.log("============================"); | ||
console.log(); | ||
} | ||
}); | ||
}; | ||
compiler.hooks.done.tap("del-webpack-plugin", callback); | ||
} | ||
} | ||
module.exports = DelWebpackPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import chalk2 from 'chalk'; | ||
import del2 from 'del'; | ||
import path2 from 'path'; | ||
|
||
var __assign = Object.assign; | ||
class DelWebpackPlugin { | ||
constructor(options) { | ||
const defaultOptions = { | ||
info: true, | ||
keepGeneratedAssets: true, | ||
exclude: [], | ||
include: ["**"], | ||
allowExternal: false | ||
}; | ||
this.options = __assign(__assign({}, defaultOptions), options); | ||
} | ||
apply(compiler) { | ||
const outputPath = compiler.options.output.path; | ||
const callback = (stats) => { | ||
if (stats.hasErrors()) { | ||
console.log(); | ||
console.log(`${chalk2.red("Del Webpack Plugin stopped according to module failed.")}`); | ||
return; | ||
} | ||
const allowExternal = this.options.allowExternal; | ||
const assetNames = stats.toJson().assets.map((asset) => asset.name); | ||
const assetPatterns = this.options.keepGeneratedAssets ? assetNames.map((name) => path2.join(outputPath, name)) : []; | ||
const includePatterns = this.options.include.map((name) => path2.join(outputPath, name)); | ||
const excludePatterns = this.options.exclude.map((name) => path2.join(outputPath, name)); | ||
const allExcludePatterns = [ | ||
outputPath, | ||
...excludePatterns, | ||
...assetPatterns | ||
]; | ||
del2(includePatterns, { | ||
force: allowExternal, | ||
ignore: allExcludePatterns | ||
}).then((paths) => { | ||
if (this.options.info) { | ||
console.log(); | ||
console.log("===== Del Webpack Plugin ==="); | ||
console.log(`${chalk2.green("Added files:")}`); | ||
assetNames.map((name) => console.log(name)); | ||
console.log(); | ||
console.log(`${chalk2.red("Deleted files:")}`); | ||
paths.map((name) => console.log(path2.basename(name))); | ||
console.log("============================"); | ||
console.log(); | ||
} | ||
}); | ||
}; | ||
compiler.hooks.done.tap("del-webpack-plugin", callback); | ||
} | ||
} | ||
module.exports = DelWebpackPlugin; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "example", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "NODE_ENV=production webpack --config webpack.example.js --progress" | ||
}, | ||
"devDependencies": { | ||
"babel-loader": "^8.1.0", | ||
"del-webpack-plugin": "file:..", | ||
"webpack": "^5.1.3", | ||
"webpack-cli": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const a = 1235 | ||
console.log(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const a = 1235 | ||
console.log(a) |
Oops, something went wrong.