Friday, 9 June 2017

Using an absolute path in webpack 2.2.1

I want to have all my node modules in the same folder, rather than copying thousands of files around with every new project. I'm no webpack expert (nor nodejs for that matter), so checking whatever Ive found online I've put together this

This is my folder setup:

PROJECT

C:\web\tests\wpack\
--webpack.config.js
--src/
----js/
------jsx/

NODE_MODULES

C:\SDKs\nodejs\node_modules\ (hundreds of folders here, including the ones I actually need)

My config file looks like this:

const webpack = require('webpack');
const path = require('path');      
const SRC_DIR = path.resolve(__dirname, 'src');
const DIST_DIR=         path.resolve(__dirname, 'dist');  

module.exports  = {
    entry: SRC_DIR + '\\js\\jsx\\index.jsx'
,devtool: 'source-map'  
  ,output: {
    path: SRC_DIR,
    filename: 'index.js'
  } 

  ,resolve: {
        modules: [path.resolve('C:\\SDKs\\nodejs',"node_modules")]
        ,extensions: ['*','.js','.jsx']
    }

  ,module : {
    loaders : [

       { test: /\.js$/, loader:  'babel-loader',  include : SRC_DIR, exclude: /node_modules/ }
      ,{ test: /\.jsx$/, loader: 'babel-loader', include : SRC_DIR, exclude: /node_modules/ } 
      ,{include: SRC_DIR,loader: "babel-loader"}


    ]
  }

  ,plugins: [
    new webpack.DefinePlugin({
            'process.env': {           
                'NODE_ENV': JSON.stringify("development") 
            }
        })           

          ]
  ,target:"web" 
  ,watch:true

};

I run webpack from the project folder like this:

node C:\SDKs\nodejs\node_modules\webpack\bin\webpack.js -p --display-error-details

And I get this:

ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in 'C:\web\tests\wpack'
resolve 'babel-loader' in 'C:\web\tests\wpack'
  Parsed request is a module
  using description file: C:\web\tests\wpack\package.json (relative path: .)
  after using description file: C:\web\tests\wpack\package.json (relative path: .)
    resolve as module
      C:\web\tests\wpack\node_modules doesn't exist or is not a directory
      C:\web\tests\node_modules doesn't exist or is not a directory
      C:\web\node_modules doesn't exist or is not a directory
      C:\node_modules doesn't exist or is not a directory

It's not even trying to look in the correct folder. Any ideas about what am I missing?

All this on windows 7x64, node 8, webpack 2

Thanks



via JimYang

No comments:

Post a Comment