1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __importStar = (this && this.__importStar) || function (mod) {
|
7 | if (mod && mod.__esModule) return mod;
|
8 | var result = {};
|
9 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
10 | result["default"] = mod;
|
11 | return result;
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack-plugin");
|
15 | const fs = __importStar(require("fs-extra"));
|
16 | const webpack = __importStar(require("webpack"));
|
17 | var WPPlugin;
|
18 | (function (WPPlugin) {
|
19 | |
20 |
|
21 |
|
22 | class FrontEndPlugin {
|
23 | constructor(buildDir, staticDir) {
|
24 | this.buildDir = buildDir;
|
25 | this.staticDir = staticDir;
|
26 | this._first = true;
|
27 | }
|
28 | apply(compiler) {
|
29 | compiler.hooks.afterEmit.tap('FrontEndPlugin', () => {
|
30 |
|
31 | if (!this.staticDir) {
|
32 | return;
|
33 | }
|
34 |
|
35 | if (this._first && fs.existsSync(this.staticDir)) {
|
36 | fs.removeSync(this.staticDir);
|
37 | }
|
38 | this._first = false;
|
39 | fs.copySync(this.buildDir, this.staticDir);
|
40 | });
|
41 | }
|
42 | }
|
43 | WPPlugin.FrontEndPlugin = FrontEndPlugin;
|
44 | |
45 |
|
46 |
|
47 | class FilterIgnorePlugin extends webpack.IgnorePlugin {
|
48 | constructor(ignored) {
|
49 | super({});
|
50 |
|
51 | this.ignored = ignored;
|
52 | }
|
53 | checkIgnore(result) {
|
54 | if (!result) {
|
55 | return result;
|
56 | }
|
57 | return this.ignored(result.resource) ? result : null;
|
58 | }
|
59 | }
|
60 | WPPlugin.FilterIgnorePlugin = FilterIgnorePlugin;
|
61 | |
62 |
|
63 |
|
64 |
|
65 | class FilterIgnoringWatchFileSystem {
|
66 | constructor(wfs, ignored) {
|
67 | this.wfs = wfs;
|
68 |
|
69 | this.ignored = ignored;
|
70 | }
|
71 | watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
72 | const notIgnored = (path) => !this.ignored(path);
|
73 | const ignoredFiles = files.filter(this.ignored);
|
74 | const ignoredDirs = dirs.filter(this.ignored);
|
75 | const watcher = this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, options, (err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps, removedFiles) => {
|
76 | if (err) {
|
77 | return callback(err);
|
78 | }
|
79 | for (const path of ignoredFiles) {
|
80 | fileTimestamps.set(path, 1);
|
81 | }
|
82 | for (const path of ignoredDirs) {
|
83 | dirTimestamps.set(path, 1);
|
84 | }
|
85 | callback(err, filesModified, dirsModified, missingModified, fileTimestamps, dirTimestamps, removedFiles);
|
86 | }, callbackUndelayed);
|
87 | return {
|
88 | close: () => watcher.close(),
|
89 | pause: () => watcher.pause(),
|
90 | getContextTimestamps: () => {
|
91 | const dirTimestamps = watcher.getContextTimestamps();
|
92 | for (const path of ignoredDirs) {
|
93 | dirTimestamps.set(path, 1);
|
94 | }
|
95 | return dirTimestamps;
|
96 | },
|
97 | getFileTimestamps: () => {
|
98 | const fileTimestamps = watcher.getFileTimestamps();
|
99 | for (const path of ignoredFiles) {
|
100 | fileTimestamps.set(path, 1);
|
101 | }
|
102 | return fileTimestamps;
|
103 | }
|
104 | };
|
105 | }
|
106 | }
|
107 | |
108 |
|
109 |
|
110 |
|
111 | class FilterWatchIgnorePlugin {
|
112 | constructor(ignored) {
|
113 | this.ignored = ignored;
|
114 | }
|
115 | apply(compiler) {
|
116 | compiler.hooks.afterEnvironment.tap('FilterWatchIgnorePlugin', () => {
|
117 | compiler.watchFileSystem = new FilterIgnoringWatchFileSystem(compiler.watchFileSystem, this.ignored);
|
118 | });
|
119 | }
|
120 | }
|
121 | WPPlugin.FilterWatchIgnorePlugin = FilterWatchIgnorePlugin;
|
122 | class NowatchDuplicatePackageCheckerPlugin extends DuplicatePackageCheckerPlugin {
|
123 | apply(compiler) {
|
124 | const options = this.options;
|
125 | compiler.hooks.run.tap('NowatchDuplicatePackageCheckerPlugin', (compiler) => {
|
126 | const p = new DuplicatePackageCheckerPlugin(options);
|
127 | p.apply(compiler);
|
128 | });
|
129 | }
|
130 | }
|
131 | WPPlugin.NowatchDuplicatePackageCheckerPlugin = NowatchDuplicatePackageCheckerPlugin;
|
132 | })(WPPlugin = exports.WPPlugin || (exports.WPPlugin = {}));
|
133 |
|
\ | No newline at end of file |