Code Monkey home page Code Monkey logo

Comments (9)

jwalton avatar jwalton commented on July 30, 2024

Oops! I'll take care of this today. I'm at an airport right now, but I
should have a moment to do this shortly. :)

-Jason
On Dec 28, 2013 8:44 AM, "Bodo Kaiser" [email protected] wrote:

Hello @benbria https://github.com/benbria

I would like to use aliasify but did not found it in the npm repository.
Could you publish it?

PS: I would prefer just passing a plain js hash to the transform as I it
makes independent from how you handle your configuration:

var builder = browserify();

builder.transform(require('./aliasify')(app.settings.aliasify));

//...

Best,
Bo


Reply to this email directly or view it on GitHubhttps://github.com//issues/2
.

from aliasify.

jwalton avatar jwalton commented on July 30, 2024

There was a lively discussion here btw, about the configuration of transform options. :)

from aliasify.

bodokaiser avatar bodokaiser commented on July 30, 2024

I do not find the discussion?

Ps: good flight!

Am 28.12.2013 um 16:23 schrieb Jason Walton [email protected]:

There was a lively discussion here btw, about the configuration of transform options. :)


Reply to this email directly or view it on GitHub.

from aliasify.

jwalton avatar jwalton commented on July 30, 2024

A link would be good. :) browserify/browserify#546

Package is now published. Working on configuring. I'm going to make it so you do:

aliasify = require('aliasify').configure(config, {configDir: __dirname});

where configDir is used to resolve relative paths in the config.

from aliasify.

bodokaiser avatar bodokaiser commented on July 30, 2024

Ah okay was on the wrong repository...

I am not aware of your implementation in detail but from my experience its the most easiest to pass it directly to the function as you suggested first in the discussion.

Example with HTML + custom parser option:

var through = require('through');

var regex = /\.[0-9a-z]+$/i;

module.exports = function(options) {

    return function(filename) {
        var template = '';

        if (!isHTMLFile(filename)) {
            return through();
        }

        var stream = through(read, end);

        function read(string) {
            template += string;
        }
        function end() {
            var module = 'module.exports =';

            if (options && options.callback) {
                template = options.callback(template);
            }
            module += JSON.stringify(template);

            this.queue(module);
            this.queue(null);
        }

        return stream;
    };
};

function isHTMLFile(filename) {
    var extension = regex.exec(filename).pop();

    return extension === '.html';
}

from aliasify.

bodokaiser avatar bodokaiser commented on July 30, 2024

I also would move the directory option into the config hash.

from aliasify.

bodokaiser avatar bodokaiser commented on July 30, 2024

I played around a bit and found also an interesting approach. Unfortunately browserify loads the file before the transform so it will always crash...

var through = require('through');

module.exports = function(options) {

    return function(filename) {
        console.log(filename);
        console.log(replace(filename, options));

        return through();
    };

};

function replace(string, options) {
    for (var key in options) {
        var path = options[key];

        if (hasPrefix(string, key)) {
            string = string.replace(key, path);
        }
    }

    return string;
}

function hasPrefix(string, prefix) {
    return string.substring(0, prefix.length) === prefix;
}

from aliasify.

jwalton avatar jwalton commented on July 30, 2024

Ok, you can now set configuration either by doing:

aliasify = require('aliasify').configure({
    aliases: {
        "d3": "./shims/d3.js"
    },
    configDir: __dirname,
    verbose: false
});

configure() returns a new instance of aliasify, so you can generate another instance of aliasify with a different configuration if you need to, without affecting the first one.

Lemme know if that works for you. Thanks!

from aliasify.

bodokaiser avatar bodokaiser commented on July 30, 2024

Yes works everything! Thank you much for your patience :)

from aliasify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.