mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
chore(core): monorepo, esm targeting, improved management (#8707)
This commit is contained in:
35
packages/webpack/plugins/PlatformSuffixPlugin.js
Normal file
35
packages/webpack/plugins/PlatformSuffixPlugin.js
Normal file
@ -0,0 +1,35 @@
|
||||
const parseFile = require("path").parse;
|
||||
|
||||
function PlatformSuffixPlugin(platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
exports.PlatformSuffixPlugin = PlatformSuffixPlugin;
|
||||
|
||||
PlatformSuffixPlugin.prototype.apply = function(resolver) {
|
||||
var platform = this.platform;
|
||||
|
||||
resolver.plugin("file", function(request, callback) {
|
||||
const fs = this.fileSystem;
|
||||
const file = this.join(request.path, request.request);
|
||||
const query = request.query;
|
||||
const pFile = parseFile(file);
|
||||
const platformFile = this.join(pFile.dir, pFile.name + ("." + platform) + pFile.ext);
|
||||
fs.stat(platformFile, (err, stat) => {
|
||||
if (!err && stat && stat.isFile()) {
|
||||
const err = undefined;
|
||||
const path = platformFile;
|
||||
callback(err, { file: true, path, query });
|
||||
} else {
|
||||
fs.stat(file, (err, stat) => {
|
||||
if (!err && stat && stat.isFile()) {
|
||||
const err = undefined;
|
||||
const path = file;
|
||||
callback(err, { file: true, path, query });
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user