Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NaridaL committed Jul 4, 2023
1 parent 5ebb50b commit cce34db
Show file tree
Hide file tree
Showing 48 changed files with 2,548 additions and 481 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-var-requires": "off",
"import/order": [
"error",
{
Expand Down
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/debug_localhost.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 57 additions & 19 deletions glsl-loader.mjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
/* eslint-disable */
import fs from "fs"
import path from "path"

function loadContent(content, filename, dependencies) {
return content.replaceAll(
/^\s*#pragma\s+webpack\s+include\s+(.*)$/gm,
(substr, what) => {
import { SourceMapGenerator } from "source-map"
function loadContent(
content,
filename,
dependencies,
resultLines,
sourceMapGenerator,
) {
const contentLines = content.split("\n")
for (let i = 0; i < contentLines.length; i++) {
const line = contentLines[i]
const match = /^\s*#pragma\s+webpack\s+include\s+(.*)$/g.exec(line)
if (match !== null) {
const [substr, what] = match
const what2 = path.resolve(path.dirname(filename), what)
if (dependencies.includes(what2)) {
return ""
} else {
if (!dependencies.includes(what2)) {
dependencies.push(what2)

return (
`// START ${what}\n` +
loadContent(
fs.readFileSync(what2, { encoding: "utf8" }),
what2,
dependencies,
) +
`\n// END ${what}`
resultLines.push(`// START ${what}`)
loadContent(
fs.readFileSync(what2, { encoding: "utf8" }),
what2,
dependencies,
resultLines,
sourceMapGenerator,
)
resultLines.push(`// END ${what}`)
}
},
)
} else {
resultLines.push(line)
try {
sourceMapGenerator.addMapping({
generated: { line: resultLines.length, column: 0 },
original: { line: i + 1, column: 0 },
source: filename,
})
} catch (e) {
console.error(e)
throw e
}
}
}
}

/**
*
* @param content {string}
* @param filename {string}
* @returns {[string,import("source-map").RawSourceMap]}
*/
function load(content, filename) {
const resultLines = []
const sourceMapGenerator = new SourceMapGenerator()
loadContent(content, filename, [], resultLines, sourceMapGenerator)
return [resultLines.join("\n"), sourceMapGenerator.toJSON()]
}

export default function (options, loaderContext, content) {
const dependencies = []
const mod = loadContent(content, loaderContext.resourcePath, dependencies)
const [mod, sourceMap] = load(
content,
loaderContext.resourcePath,
dependencies,
)
let code = `
export default ${JSON.stringify(mod)}
const sourceMap = ${JSON.stringify(sourceMap)}
export { sourceMap };
`
if (loaderContext.hot) {
code += `
Expand Down
Loading

0 comments on commit cce34db

Please sign in to comment.