fix: node_modules resolutions

This commit is contained in:
Guy Bedford 2021-08-26 13:18:31 -07:00 committed by Ralf Becker
parent 4218b132f9
commit 2526b0460e
2 changed files with 20 additions and 3 deletions

View File

@ -9,7 +9,7 @@
*/
import {css, html} from "../../../../node_modules/@lion/core/index.js";
import {css, html} from "@lion/core";
import {LionButton} from "../../../../node_modules/@lion/button/index.js";
import {SlotMixin} from "../../../../node_modules/@lion/core/src/SlotMixin.js";
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";

View File

@ -23,6 +23,18 @@ rimraf.sync('./chunks/');
// Turn on minification
const do_minify = false;
function isBareSpecifier (id) {
if (id.startsWith("./") || id.startsWith("../") || id.startsWith("/"))
return false;
try {
new URL(id);
return false;
}
catch {
return true;
}
}
const config = {
treeshake: false,
input: {
@ -58,13 +70,18 @@ const config = {
},
plugins: [{
resolveId (id, parentId) {
// Delegate bare specifiers to node_modules resolver
if (isBareSpecifier(id))
{
return;
}
if (!parentId || parentId.indexOf(path.sep + 'node_modules' + path.sep) !== -1)
{
return;
}
if(id.endsWith(".js"))
if (id.endsWith(".js"))
{
const tsPath =path.resolve(path.dirname(parentId), id.slice(0,-3) + '.ts');
const tsPath = path.resolve(path.dirname(parentId), id.slice(0,-3) + '.ts');
try {
readFileSync(tsPath);
console.warn(id + " is a TS file loaded with wrong extension. Remove the extension on the import in " + parentId);