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