1 | const parseFile = require("path").parse;
|
2 |
|
3 | function PlatformSuffixPlugin(platform) {
|
4 | this.platform = platform;
|
5 | }
|
6 | exports.PlatformSuffixPlugin = PlatformSuffixPlugin;
|
7 |
|
8 | PlatformSuffixPlugin.prototype.apply = function(resolver) {
|
9 | var platform = this.platform;
|
10 |
|
11 | resolver.plugin("file", function(request, callback) {
|
12 | const fs = this.fileSystem;
|
13 | const file = this.join(request.path, request.request);
|
14 | const query = request.query;
|
15 | const pFile = parseFile(file);
|
16 | const platformFile = this.join(pFile.dir, pFile.name + ("." + platform) + pFile.ext);
|
17 | fs.stat(platformFile, (err, stat) => {
|
18 | if (!err && stat && stat.isFile()) {
|
19 | const err = undefined;
|
20 | const path = platformFile;
|
21 | callback(err, { file: true, path, query });
|
22 | } else {
|
23 | fs.stat(file, (err, stat) => {
|
24 | if (!err && stat && stat.isFile()) {
|
25 | const err = undefined;
|
26 | const path = file;
|
27 | callback(err, { file: true, path, query });
|
28 | } else {
|
29 | callback();
|
30 | }
|
31 | });
|
32 | }
|
33 | });
|
34 | });
|
35 | }
|