Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Readme, add tests, add webpack 4 support
- Loading branch information
pqml
committed
Mar 5, 2018
1 parent
5dc4eea
commit c75fb47
Showing
25 changed files
with
320 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
# Editors | ||
.idea | ||
.vscode | ||
|
||
# Node / Yarn / Npm | ||
node_modules | ||
npm-debug.log* | ||
yarn.lock | ||
package-lock.json | ||
|
||
# Logs and Temporary files | ||
.tmp | ||
logs | ||
*.log | ||
|
||
# MacOS | ||
.DS_Store | ||
bundle.js | ||
.AppleDouble | ||
.LSOverride | ||
Icon | ||
._* | ||
|
||
# Misc | ||
coverage |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const path = require('path') | ||
const loaderUtils = require('loader-utils') | ||
const resolve = require('resolve') | ||
const deps = require('glslify-deps') | ||
const bundle = require('glslify-bundle') | ||
|
||
module.exports = function glslifyLoader (content) { | ||
this.cacheable && this.cacheable() | ||
|
||
const depper = deps() | ||
const callback = this.async() | ||
|
||
// Setup options | ||
const options = Object.assign({ | ||
basedir: path.dirname(this.resourcePath), | ||
transform: [] | ||
}, loaderUtils.getOptions(this)) | ||
|
||
// Handle transforms from options | ||
const transforms = Array.isArray(options.transform) ? options.transform : [] | ||
const postTransforms = [] | ||
transforms.forEach(transform => { | ||
if (!Array.isArray(transform)) transform = [String(transform)] | ||
const name = transform[0] | ||
const opts = transform[1] || {} | ||
// Keep post-transforms for later | ||
if (opts.post) postTransforms.push({ name, opts }) | ||
else depper.transform(name, opts) | ||
}) | ||
|
||
// Build the dependency graph | ||
depper.inline(content, options.basedir, (err, tree) => { | ||
if (err) return error(err) | ||
// Make webpack watch each subdependencies | ||
tree && tree.forEach(file => !file.entry && this.addDependency(file.file)) | ||
// Bundle the glsl output | ||
const output = String(bundle(tree)) | ||
// Start applying post transforms | ||
nextPostTransform(null, output) | ||
}) | ||
|
||
// Iterate over each post transforms | ||
function nextPostTransform (err, output) { | ||
if (err) return error(err) | ||
const transform = postTransforms.shift() | ||
if (!transform) return done(output) | ||
resolve(transform.name, { basedir: options.basedir }, (err, target) => { | ||
if (err) return error(err) | ||
require(target)(null, output, transform.opts, nextPostTransform) | ||
}) | ||
} | ||
|
||
function error (err) { | ||
callback(err, null) | ||
} | ||
|
||
function done (output) { | ||
callback(null, output) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.