emaphp / underscore-template-loader

A Underscore and Lodash template loader for Webpack
MIT License
104 stars 24 forks source link

Register on bower #2

Closed irishkurisu closed 8 years ago

irishkurisu commented 8 years ago

It would be really useful to have this registered on bower, as well as npm.

http://bower.io/docs/creating-packages/

emaphp commented 8 years ago

is that even possible? i've never heard of webpack loaders installed through bower but i'll do my research. i'll let you know if i come up with something

irishkurisu commented 8 years ago

It is possible but not highly recommended by webpack, so I totally understand why you never did. I have my hand a bit forced, though, because of some other packages that are only available on bower and we are exploring moving to either one or the other.

emaphp commented 8 years ago

I did my research and I couldn't find a way to run a loader reading from the bower_components dir. This might have to do with the way dependencies are managed in webpack (not a webpack expert tbh) .You can however load modules installed through bower.

main.js

var $ = require('jquery');
var _ = require('underscore');
var tpl = require('../templates/hello_world.html');

$(function () {
    $('#content').html(tpl({message: 'Hello'}));
});

webpack.config.js

var path = require("path");
var webpack = require("webpack");

module.exports = {
    entry: "./js/main.js",

    output: {
        path: __dirname,
        filename: "bundle.js"
    },

    node: {
        fs: "empty"
    },

    module: {
        loaders: [
            { test: /\.html/, loader: "underscore-template-loader" }
        ]
    },

    resolve: {
        root: [path.join(__dirname, "bower_components")]
    },

    plugins: [
        new webpack.ResolverPlugin(
            new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
        )
    ]
};