Skip to content

I'm having trouble setting up the absolute paths for an non-default directory structure #10

@dschissler

Description

@dschissler

I've been chipping away at the features and I've had success doing a lot of things with webpack. One thing that has plagued me for sometime is setting up a directory structure where the conf, bower and node modules are stored in a directory that is a sibling of the directory where my custom modules are stored.

I'm receiving the following error

ERROR in Entry module not found: Error: Cannot resolve module coffee-loader in /usr/local/webprojects/webpack/app/modules
resolve module coffee-loader in /usr/local/webprojects/webpack/app/modules

Note that I was successfully working with my node and bower directories being in different places before. Something about the absolute path situation is messing my project up, since it is not on the same branch.

My project is laid out like the following:

project
    build
        bower_components
        node_modules
        bower.json
        package.json
        webpack.config.js
    app
        modules (custom/proprietary commonjs modules)
        php
        view (Phalcon Volt partials)
        config (json configs so that socket.io and php can both connect)
        public
            index.php
    dist
        [working stuff will go here and will be fetched in the debug PHP template]

test might go inside of build or on the top level

I've set it up like this since PHP compilation will be a feature of this framework/scaffold


var path = require('path');
var webpack = require('webpack');
var console = require('console');

var resolveBowerPath = function(componentPath) {
    return path.join(__dirname, 'bower_components', componentPath);
};
var resolveNodePath = function(componentPath) {
    return path.join(__dirname, 'node_modules', componentPath);
};
var resolveModulePath = function(itemPath) {
    var appPath = path.resolve('../app');
    return path.join(appPath, 'modules', itemPath);
};


console.log(resolveBowerPath(''));
console.log(resolveNodePath(''));
console.log(resolveModulePath(''));
console.log(path.resolve('../app') + '/public/bundle');


module.exports = {
    cache: true,
    context: resolveModulePath(''),

    entry: {
      entryMain: './entryMain'
//      entryLogin: './entryLogin'
    },

    output: {
//        path: __dirname + '/public/bundle',
        path: path.resolve('../app') + '/public/bundle',
        publicPath: '/bundle/',
        filename: "[name].bundle.js",
        chunkFilename: '[id].bundle.js'
    },

    resolve: {
//        root: resolveModulePath(''),
        root: [resolveBowerPath(''), resolveNodePath(''), resolveModulePath('')],
        // tells webpack to query these directories for modules
//        modulesDirectories: ['bower_components', 'node_modules'],
        modulesDirectories: [resolveBowerPath(''), resolveNodePath(''), resolveModulePath('')],
//        modulesDirectories: ['./bower_path', './node_modules', resolveModulePath('')],

        alias: {
            lodash: resolveBowerPath('/lodash/dist/lodash'),
            jquery: resolveBowerPath('/jquery/dist/jquery'),
            angular: resolveBowerPath('/angular/angular'),
            angularRouter: resolveBowerPath('/angular-ui-router/release/angular-ui-router'),
            angularCookies: resolveBowerPath('/angular-cookies/angular-cookies'),
            angularResource: resolveBowerPath('/angular-resource/angular-resource'),
        },
        extensions: [
            '',
            '.js', '.coffee',
            '.html', '.jade',
            '.css', '.styl', '.scss', '.less'
        ]        
    },
    plugins: [
        new webpack.ProvidePlugin({
            _: 'lodash',
        }),
        // this plugin makes webpack not only looking for package.json, but also for a bower.json with a main-field
        new webpack.ResolverPlugin([
            new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
        ]),
        new webpack.DefinePlugin({
          VERSION: JSON.stringify('alpha'),
          DEVEL: true
        })
    ],

    module: {
        loaders: [
            // Exports Angular
            { test: /[\/]angular\.js$/, loader: "exports?angular" },
            // Script Loaders
//            { test: /\.coffee$/, loader: "coffee" },
            { test: /\.coffee$/, loader: "coffee-loader" },

            { test: /\.html$/, loader: "html" },
//            { test: /\.jade$/, loader: "jade" },
            { test: /\.jade$/, loader: "template-html-loader" },
            // Style Loaders, style! inlines the css into the bundle files
            { test: /\.css$/, loader: "style!css" },
            { test: /\.scss$/, loader: "style!css!sass" },
            { test: /\.less$/, loader: "style!css!less" },
            { test: /\.styl$/, loader: "style!css!stylus" }
        ]
    }

};

I've tried a variety of things and this is what I have at the moment. So, I'm missing something small and obvious right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions