GithubHelp home page GithubHelp logo

babel-plugin-webpack-loaders's Introduction

Travis CI Appveyor

babel-plugin-webpack-loaders

Important note!!!

Since plugin was published, there were a lot of changes in testing software. Be sure in most(all) cases you DON'T need this plugin for testing. I highly recommend you to use jest for testing, and use moduleNameMapper (identity-obj-proxy, etc) to mock CSS-Modules and other webpack loaders.

Begin

This Babel 6 plugin allows you to use webpack loaders in Babel. It's now easy to run universal apps on the server without additional build steps, to create libraries as usual with babel src --out-dir lib command, to run tests without mocking-prebuilding source code. It just replaces require - import statements with webpack loaders results. Take a look at this Babel build output diff to get the idea.

For now this plugin is of alpha quality and tested on webpack loaders I use in my projects. These loaders are file-loader, url-loader, css-loader, style-loader, sass-loader, postcss-loader. The plugin supports all webpack features like loaders chaining, webpack plugins, and all loaders params. It's easy because this plugin just uses webpack.

Three examples:

Warning

Do not run this plugin as part of a webpack frontend configuration. This plugin is intended only for backend compilation.

How it works

Take a look at this minimal-example

  • You need to create a webpack config

  • You need to add these lines to .babelrc

  • Now you can run example.js

    // example.js
    import css from './example.css';
    console.log('css-modules result:', css);

    with the command BABEL_DISABLE_CACHE=1 NODE_ENV=EXAMPLE ./node_modules/.bin/babel-node ./example.js and you'll get the following console output:

    css-modules result: { main: 'example__main--zYOjd', item: 'example__item--W9XoN' }

Here I placed output diff of this babel library build without and with the plugin. As you can see the plugin just replaces require with loaders results. All loaders and plugins have been applied to generated assets

Install

npm install --save-dev babel-cli babel-plugin-webpack-loaders

Examples

webpack configs, examples, .babelrc example, tests, minimal-example-repo

You can try out the examples by cloning this repo and running the following commands:

npm install
# example above
npm run example-run
# library example - build library with a lot of modules
npm run example-build
# and now you can use your library using just node
node build/myCoolLibrary/myCoolLibrary.js
# test sources are also good examples
npm run test

Why

The source of inspiration for this plugin was babel-plugin-css-modules-transform, but it was missing some features I wanted:

  • I love writing CSS using Sass
  • I like webpack and its loaders (chaining, plugins, settings)
  • I wanted to open source a UI library which heavily used CSS Modules, Sass and other webpack loaders. The library consisted of many small modules and every module needed to be available to users independently such as lodash/blabla/blublu. With this plugin the heavy build file for the library could be replaced with just one command: babel src --out-dir lib.

How the plugin works internally

The plugin tests all require paths with test regexps from the loaders in the webpack config, and then for each successful test:

  1. synchronously executes webpack

  2. parses webpack output using babel-parse

  3. replaces the required ast with the parsed ast output

Caching issues

By default Babel caches compiled files, so any changes in files processed with loaders will not be visible at subsequent builds, you need to run all commands with a BABEL_DISABLE_CACHE=1 prefix.

(More information: #T1186, #36)

Dynamic config path

It's possible to interpolate env vars into the WebPack config path defined in your .babelrc using lodash.template syntax. This is mainly to achieve compatibility with ava.

The ava test runner runs each spec relative to its enclosing folder in a new process which hampers this plugins ability to use a relative path for the WebPack config. An absolute path to the WebPack config will work however, and you can set one in your .babelrc using an env var like this,

{
  "presets": ["es2015"],
  "env": {
    "AVA": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "${CONFIG}",
            "verbose": false
          }
        ]
      ]
    }
  }
}

And then invoke ava something like this,

CONFIG=$(pwd)/webpack.config.ava.js BABEL_DISABLE_CACHE=1 NODE_ENV=AVA ava --require babel-register src/**/*test.js

(More information: #41)

Thanks to

Felix Kling and his astexplorer

James Kyle and his babel-plugin-handbook

Michal Kvasniฤรกk and his babel-plugin-css-modules-transform

babel-plugin-webpack-loaders's People

Contributors

fusepilot avatar gabemedrash avatar greenkeeperio-bot avatar istarkov avatar jedrichards avatar jhicken avatar kale1d0code avatar karlhorky avatar moox avatar nkbt avatar ntharim avatar sosana avatar stevoland avatar tikotzky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-plugin-webpack-loaders's Issues

Doesn't work with AVA tests in separate processes

I think this issue has already been noted here #4 (comment) but thought it would be worth making a dedicated issue, since it looks like no solution has been found?

The ava test runner runs each file under test in a new process, so I think this has the effect of adjusting the pwd to the folder of the current file and breaking this plugins ability to find the webpack config.

So a babel config that looks like,

{
  "presets": ["es2015"],
  "env": {
    "AVA": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "./webpack.config.ava.js",
            "verbose": false
          }
        ]
      ]
    }
  }
}

breaks with an error,

Cannot find module '/Users/jed/work/project/components/text-control/webpack.config.ava.js'

If I change the config to the below it works perfectly, but obviously the absolute filepath is no good on a shared project ...

{
  "presets": ["es2015"],
  "env": {
    "AVA": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "/Users/jed/work/project/webpack.config.ava.js",
            "verbose": false
          }
        ]
      ]
    }
  }
}

Any body got any ideas? I would be happy to try and prepare a PR ... but not sure what approach to take ...

"Cannot find module" on Windows 10

@istarkov

Currently using your plugin on with mern-starter but an issue with various users using windows had the error "Cannot find module". Details for the problem and quick fix are detailed here as it turns out these where the directions to fix the problem

Open ~\node_modules\babel-plugin-webpack-loaders\lib\runWebPackSync.js

Go to line 41, replace

var webPackStdOut = (0, _child_process.execSync)((0, _shellQuote.quote)(['node', webPackPath, path, outPath, '--config', configPath, '--bail']));

with

var webPackStdOut = (0, _child_process.execSync)(['node', webPackPath, path, outPath, '--config', configPath, '--bail'].join(' '));

Should we create a pr with this adjustment or did you want to look into this and give thoughts?

Devtool cheap-module-eval-sourcemap causes css module import to return undefined

Hello!
Was having some trouble with ava tests where css module imports would return undefined, decided to play with the examples provided with the repo. If i modify test/runtime.webpack.config.babel.js to include the following:

...

export default {
  devtool: 'cheap-module-eval-source-map',
  output: {
    // YOU NEED TO SET libraryTarget: 'commonjs2'
    libraryTarget: 'commonjs2',
  },
  module: {
    loaders: [

...

i get this error running npm run ava-test:

โœ– ava withoutExtractText test
  t.deepEqual(css, { item: 'style__item', main: 'style__main' })
              |
              null


  1 test failed

  1. ava withoutExtractText test
  AssertionError: undefined === { item: 'style__item', main: 'style__main' }

if I specify devtool as undefined, sourcemap, or leave it out of the config, it all works fine. Maybe this just needs to be documented somewhere?

Thanks!

Fails with jsdom

I've been trying to include jsdom in my tests, and it is failing on trying to resolve the fs module used within jsdom.

component.test.js

const jsdom = require('jsdom');

// OR

import jsdom from 'jsdom';

Error

ModuleNotFoundError: Module not found: Error: Cannot resolve module 'fs' in /Users/karlhorky/projects/k/node_modules/jsdom/lib

webpack config

const path = require('path');

module.exports = {
  module: {
    loaders: []
  },
  resolve: {
    modules: [
      __dirname,
      path.resolve(__dirname, 'node_modules')
    ]
  },
  output: {
    libraryTarget: 'commonjs2'
  }
};

Weird ReferenceError when using a custom webpack loader

Hi, I'm trying to use your plugin with this custom webpack loader. The loader produces code that looks roughly like this:

var requireMap = {

};
function requireInRuntime(path) {
    if (!requireMap.hasOwnProperty(path)) {
        throw new Error("require() statements can be added only by editing a Markdown example file.")
    }
    return requireMap[path];
}
module.exports = [
  {
    "type": "code",
    "content": "<div><Button>default</Button></div>",
    "evalInContext": function(code, setState) {   var require = requireInRuntime;   return eval(code);}
  },
  // ...
];

When I require stuff using this loader, it loads fine, but then, when I call the evalInContext function it fails with:

     ReferenceError: requireInRuntime is not defined
      at Object.evalInContext (mochatest.js:13:9)
      at Context.<anonymous> (mochatest.js:20:30)

This is kinda weird because requireInRuntime is defined in the same file, in the file scope.

I couldn't believe this error and copied the loader output to an examples.js file but then it works fine.

CSS modules compose from other file fails

Hello again!

Was having trouble getting ava tests working when composing css modules between files. Tried modifying some of the provided examples to investigate.

Modified test/assets/withoutExtractText/style.css to the following (having added the referenced file and style to the folder):

.main {
  composes: othermain from 'postcss!./otherstyle.css';
  width: 100%;
}

.item {
  height: 100%;
}

and got this error when running npm run ava-test:

babel-plugin-webpack-loaders (master) โœ— npm run ava-test

> [email protected] ava-test /Users/kav/lib/babel-plugin-webpack-loaders
> CONFIG=$(pwd)/test/runtime.webpack.config.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=AVA_TEST ava


/Users/kav/lib/babel-plugin-webpack-loaders/test/ava/index.js:10
  "main": "style__main " + __webpack_require__(0).locals["othermain"] + "",
                           ^

ReferenceError: __webpack_require__ is not defined
    at Object.<anonymous> (/Users/kav/lib/babel-plugin-webpack-loaders/test/ava/index.js:2:1)
    at Module._compile (module.js:541:32)
    at extensions.(anonymous function) (/Users/kav/lib/babel-plugin-webpack-loaders/node_modules/require-precompiled/index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/kav/lib/babel-plugin-webpack-loaders/node_modules/ava/lib/test-worker.js:89:3)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/kav/lib/babel-plugin-webpack-loaders/node_modules/ava/lib/test-worker.js:93:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:449:3
  โœ– test/ava/index.js exited with a non-zero exit code: 1

  0 tests passed
  1 uncaught exception


npm ERR! Darwin 15.5.0
npm ERR! argv "/Users/kav/.nvm/versions/node/v6.2.0/bin/node" "/Users/kav/.nvm/versions/node/v6.2.0/bin/npm" "run" "ava-test"
npm ERR! node v6.2.0
npm ERR! npm  v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] ava-test: `CONFIG=$(pwd)/test/runtime.webpack.config.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=AVA_TEST ava`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] ava-test script 'CONFIG=$(pwd)/test/runtime.webpack.config.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=AVA_TEST ava'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the babel-plugin-webpack-loaders package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     CONFIG=$(pwd)/test/runtime.webpack.config.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=AVA_TEST ava
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs babel-plugin-webpack-loaders
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls babel-plugin-webpack-loaders
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/kav/lib/babel-plugin-webpack-loaders/npm-debug.log

same thing happens if use

.main {
  composes: othermain from './otherstyle.css';
  width: 100%;
}

Thanks!

CSS Composes/from paths not resolved

I'm using babel-plugin-webpack-loader with the following config

module.exports = {
  output: {
    libraryTarget: 'commonjs2',
  },
  resolve: {
    modules: [
      srcPath,
      nodeModulesPath,
    ],
    extensions: ['', '.js', '.jsx', '.css', '.scss', '.sass'],
  },
  module: {
    loaders: [
      {
        test: /\.scss$|\.sass$|\.css$/,
        loaders: [
          'style',
          'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
          'sass',
        ],
        include: srcPath,
      },
    ],
  },
  sassLoader: {
    includePaths: [srcPath],
  },
}

srcPath references the root of my application
It contains a folder called styles

something like this works fine:
@import 'styles/variables'

this also works
import 'styles/main'

but, when using css modules, something like this does not work:

.text
  composes: text from 'styles/shared/card'

Instead, in order to get it to work, I am forced to do this

.text
  composes: text from '../../styles/shared/card'

is this expected behavior? are paths within composes not resolved using the webpack config?

Seems to ignore dynamic requires

I'm using the require babel hook. Everything seemed to work fine until i changed my imports to requires. seems to work fine with the css-modules-require-hook but that doesn't support async plugins.

After i change it to a require, it seems to give me this error, which means it's being processed as javascript and not as css

Unexpected token (1:0)
> 1 | .revealer

bundling multiple css files

I have a css-modules project/library and I'm trying to get all the css exported into 1 css file using this plugin and ExtractTextPlugin()

plugins: [ new ExtractTextPlugin('main.css') ]

However, what ends up happening, is instead of the multiple CSS files getting inserted into main.css, instead each css file just overwrites the next one.

Improve speed/cache

Currently we (advise to) disable all the cache but that can be pretty slow and not super relevant when you run a lot of tests (eg via AVA).
Maybe we should find a way to use another cache and "just" delete this cache when starting a process, so a runtime cache can be used (when I run a lot of tests, it's very probable that I don't update any file during the command runtime)
Any thoughts.?

import statement returns undefined

I'm trying to use this plugin to compile react templates on the server - see the webpack plugin.

Here are my configuration settings.

server/config/webpack.js

module.exports = {
  output: {
    libraryTarget: 'commonjs'
  },
  module: {
    loaders: [
      {
        test: /\.template\.html$/,
        loaders: ["react-templates-loader?targetVersion=0.14.0"]
      },
    ],
  },
};

.babelrc

{
  "presets": ["es2015", "react"],
  "plugins": [
    ["babel-plugin-webpack-loaders",
      { "config": "./server/config/webpack.js",
        "verbose": false } ]
  ]
}

An example template:
components/layout/layout.template.html

<div id="layout">
  <h1>Basic Layout Component</h1>
  <div rt-if="!this.state.example" class="alert alert-warning">
    Choose an example.
  </div>
  <div rt-if="this.state.example" class="alert alert-info">
    {this.state.example.introduce()}
  </div>
  <div class="btn-group" role="group">
    <button
      rt-repeat="example in this.examples"
      key="{example.scoped_id}"
      data-param="example_id"
      data-value="{example.data.id}"
      rt-class="{active: this.example && this.example.data.id === example.data.id}"
      onClick="{this.setParam.bind(this)}"
      type="button" class="btn btn-primary">{example.data.name}</button>
  </div>
</div>

And the related React Component:
components/layout/layout.component.js

import React from 'react';
import template from 'layout.template.html';

class Layout extends React.Component {
  // ...
  render(){
   // note this works as intended when compiled with pure Webpack.
  console.log(template);
   return template.call(this);
  }
}

Unfortunately, template is undefined when I run with this plugin. In fact, I've put some log statements into node_modules/react-templates-loader/index.js and it seems the loader is never even called.

I'd be willing to put some time into making this work, but I really don't where to start. Do you have any idea where to start in terms of debugging this?

Does not run webpack loader on files imported from node modules

I'm trying to use react-toolbox in a project with babel-plugin-webpack-loaders for server-side rendering. react-toolbox imports raw Sass templates, so I was expecting this plugin to process them via webpack just like everything else.

I noticed that if I import one of the Sass templates directly in my code, it does get processed by the webpack loaders from the plugin. However if I let react-toolbox handle the import (which is the only way to import the components anyway), it doesn't run them through the Sass loader.

Here's a simple repo to reproduce both failing and working examples (run node fail or node pass).

Any way to skip outputPath/main.*.css ?

I guess under the hood it's a normal behavior to get lot's of css files when you use css modules. That said, in my case (universal code), I have a builded css file for client side, so I do not need all those files in my build folder. Any idea how I can safely remove or even better, skip them when using your babel plugin?

ModuleNotFoundError: Cannot resolve module 'fs' on versions above 0.2.3

After the last updates:

โœ˜-127 ~/nkbt/react-component-template [eslint2 L|โœ”] 
16:50 $ NODE_ENV=test `npm bin`/babel-node test
ModuleNotFoundError: Module not found: Error: Cannot resolve module 'fs' in /Users/nkbt/nkbt/react-component-template/node_modules/glob
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:726:13
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:52:16
    at done (/Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:241:17)
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:44:16
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:723:17
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:167:37
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at innerCallback (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:94:11)
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/ModulesInDirectoriesPlugin.js:54:23
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/ModulesInDirectoriesPlugin.js:45:26
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:33
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/FileAppendPlugin.js:31:26)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/FileAppendPlugin.js:28:12
    at Storage.finished (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at FSReqWrap.oncomplete (fs.js:83:15)
resolve module fs in /Users/nkbt/nkbt/react-component-template/node_modules/glob
  looking for modules in /Users/nkbt/nkbt/react-component-template/node_modules
    /Users/nkbt/nkbt/react-component-template/node_modules/fs doesn't exist (module as directory)
    resolve 'file' fs in /Users/nkbt/nkbt/react-component-template/node_modules
      resolve file
        /Users/nkbt/nkbt/react-component-template/node_modules/fs doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.webpack.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.web.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.json doesn't exist
/Users/nkbt/nkbt/react-component-template/node_modules/babel-core/lib/transformation/file/index.js:585
      throw err;
      ^

Error: /Users/nkbt/nkbt/react-component-template/test/index.js: Command failed: node /Users/nkbt/nkbt/react-component-template/node_modules/webpack/bin/webpack.js /Users/nkbt/nkbt/react-component-template/node_modules/glob/glob.js /var/folders/tj/yys527ld7wdbf9lfh244hk_h0000gn/T/.webpack.res.1455601819228_528818.js --config ./webpack.config.js --colors --bail
ModuleNotFoundError: Module not found: Error: Cannot resolve module 'fs' in /Users/nkbt/nkbt/react-component-template/node_modules/glob
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:726:13
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:52:16
    at done (/Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:241:17)
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:44:16
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:723:17
    at /Users/nkbt/nkbt/react-component-template/node_modules/async/lib/async.js:167:37
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at innerCallback (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:94:11)
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/ModulesInDirectoriesPlugin.js:54:23
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/ModulesInDirectoriesPlugin.js:45:26
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:122:33
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/FileAppendPlugin.js:31:26)
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at /Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/FileAppendPlugin.js:28:12
    at Storage.finished (/Users/nkbt/nkbt/react-component-template/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at FSReqWrap.oncomplete (fs.js:83:15)
resolve module fs in /Users/nkbt/nkbt/react-component-template/node_modules/glob
  looking for modules in /Users/nkbt/nkbt/react-component-template/node_modules
    /Users/nkbt/nkbt/react-component-template/node_modules/fs doesn't exist (module as directory)
    resolve 'file' fs in /Users/nkbt/nkbt/react-component-template/node_modules
      resolve file
        /Users/nkbt/nkbt/react-component-template/node_modules/fs doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.webpack.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.web.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.js doesn't exist
        /Users/nkbt/nkbt/react-component-template/node_modules/fs.json doesn't exist

    at checkExecSyncError (child_process.js:465:13)
    at execSync (child_process.js:505:13)
    at exports.default (/Users/nkbt/nkbt/react-component-template/node_modules/babel-plugin-webpack-loaders/lib/runWebPackSync.js:41:51)
    at PluginPass.CallExpression (/Users/nkbt/nkbt/react-component-template/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:76:60)
    at newFn (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/visitors.js:293:19)
    at NodePath._call (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/path/context.js:74:18)
    at NodePath.call (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/path/context.js:46:17)
    at NodePath.visit (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/path/context.js:104:12)
    at TraversalContext.visitQueue (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:156:16)
    at TraversalContext.visitSingle (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:113:19)
    at TraversalContext.visit (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:200:19)
    at Function.traverse.node (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/index.js:139:17)
    at NodePath.visit (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/path/context.js:114:22)
    at TraversalContext.visitQueue (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:156:16)
    at TraversalContext.visitMultiple (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:108:17)
    at TraversalContext.visit (/Users/nkbt/nkbt/react-component-template/node_modules/babel-traverse/lib/context.js:198:19)
โœ˜-1 ~/nkbt/react-component-template [eslint2 L|โœ”] 

Disabling babel-plugin-webpack-loaders (and css import) make tests running again.

Stepping down to 0.2.3 fixes the problem too.

16:54 $ npm install [email protected]
[email protected] /Users/nkbt/nkbt/react-component-template
โ”œโ”€โ”€ [email protected]  extraneous
โ””โ”€โ”€ UNMET PEER DEPENDENCY [email protected]

โœ” ~/nkbt/react-component-template [eslint2 L|โœ”] 
16:55 $ NODE_ENV=test `npm bin`/babel-node test
TAP version 13
# Component
ok 1 should be function
# App
ok 2 should be function

1..2
# tests 2
# pass  2

# ok

โœ” ~/nkbt/react-component-template [eslint2 L|โœ”] 

Cannot read property 'some' of undefined

I am trying to running test on a ReactJS codebase with CSS modules.
When I run the test with Ava, I receive the following message

TypeError: /client/setup.js: Cannot read property 'some' of undefined
    at PluginPass.CallExpression (/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:81:34)

setup.js contains the initialization of jsdom

import jsdom from 'jsdom'

global.document = jsdom.jsdom('<html><body></body></html>')
global.window = document.defaultView
global.navigator = window.navigator

Could you point me in the right direction for the solution?
Cheers.

Cannot resolve .webpack.res.1462025829429_520036.js

Hi, I am trying to using this loader to test a ReactJS application with Ava test runner.
Probably I am doing something wrong with the configuration, but I can't understand.
This is how I launch Ava
CONFIG=$(pwd)/webpack.config.js BABEL_DISABLE_CACHE=1 NODE_ENV=test ava.

And this is my .babelrc

{
  "plugins": ["lodash"],
  "presets": ["es2015", "react"],
  "env": {
    "test": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": "${CONFIG}",
            "verbose": false,
          }
        ]
      ]
    }
  }
}

This is the test I am trying to execute

import React from 'react'
import { shallow } from 'enzyme'
import '../setup'
import test from 'ava'
import Sidebar from './Sidebar'
import Content from './Content'
import Front from './Front'

test('<Front /> root component', (t) => {
  const wrapper = shallow(<Front />)

  t.is(wrapper.find(Sidebar).length, 1)
  t.is(wrapper.find(Content).length, 1)
})

What are these .webpack.res files that it is not finding?

ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' public/test/.webpack.res.1462025829429_520036.js in client/front
    at node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at node_modules/async/lib/async.js:726:13
    at node_modules/async/lib/async.js:52:16
    at done (node_modules/async/lib/async.js:241:17)
    at node_modules/async/lib/async.js:44:16
    at node_modules/async/lib/async.js:723:17
    at node_modules/async/lib/async.js:167:37
    at node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at node_modules/enhanced-resolve/lib/Resolver.js:127:10
    at node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (node_modules/enhanced-resolve/lib/DirectoryDescriptionFilePlugin.js:24:12)
    at Storage.finished (node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at ReadFileContext.callback (node_modules/graceful-fs/graceful-fs.js:78:16)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)
resolve file
  public/test/.webpack.res.1462025829429_520036.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.webpack.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.web.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.json doesn't exist
resolve directory
  public/test/.webpack.res.1462025829429_520036.js doesn't exist (directory default file)
  public/test/.webpack.res.1462025829429_520036.js/package.json doesn't exist (directory description file)
node_modules/babel-core/lib/transformation/file/index.js:556
      throw err;
      ^

Error: client/front/Sidebar/Sidebar.js: Command failed: node node_modules/webpack/bin/webpack.js client/front/Sidebar/sidebar.css public/test/.webpack.res.1462025829429_520036.js --config webpack.config.js --bail
ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' public/test/.webpack.res.1462025829429_520036.js in client/front
    at node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at node_modules/async/lib/async.js:726:13
    at node_modules/async/lib/async.js:52:16
    at done (node_modules/async/lib/async.js:241:17)
    at node_modules/async/lib/async.js:44:16
    at node_modules/async/lib/async.js:723:17
    at node_modules/async/lib/async.js:167:37
    at node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at node_modules/enhanced-resolve/lib/Resolver.js:127:10
    at node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (node_modules/enhanced-resolve/lib/DirectoryDescriptionFilePlugin.js:24:12)
    at Storage.finished (node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at ReadFileContext.callback (node_modules/graceful-fs/graceful-fs.js:78:16)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)
resolve file
  public/test/.webpack.res.1462025829429_520036.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.webpack.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.web.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.js doesn't exist
  public/test/.webpack.res.1462025829429_520036.js.json doesn't exist
resolve directory
  public/test/.webpack.res.1462025829429_520036.js doesn't exist (directory default file)
  public/test/.webpack.res.1462025829429_520036.js/package.json doesn't exist (directory description file)

    at checkExecSyncError (child_process.js:469:13)
    at execSync (child_process.js:509:13)
    at exports.default (node_modules/babel-plugin-webpack-loaders/lib/runWebPackSync.js:41:51)
    at PluginPass.CallExpression (node_modules/babel-plugin-webpack-loaders/lib/plugin.js:89:60)
    at newFn (node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:184:19)
    at Function.traverse.node (node_modules/babel-traverse/lib/index.js:135:17)
    at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:103:22)
    at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:110:17)
    at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:182:19)
    at Function.traverse.node (node_modules/babel-traverse/lib/index.js:135:17)
    at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:103:22)
    at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:184:19)
    at Function.traverse.node (node_modules/babel-traverse/lib/index.js:135:17)
    at Object.traverse [as default] (node_modules/babel-traverse/lib/index.js:69:12)
    at node_modules/babel-core/lib/transformation/file/index.js:513:33
    at Array.forEach (native)
    at File.transform (node_modules/babel-core/lib/transformation/file/index.js:510:23)
    at node_modules/babel-core/lib/transformation/pipeline.js:49:19
    at File.wrap (node_modules/babel-core/lib/transformation/file/index.js:528:16)
    at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:17)
    at Object.transformFileSync (node_modules/babel-core/lib/api/node.js:124:10)
    at compile (node_modules/babel-register/lib/node.js:98:20)
    at loader (node_modules/babel-register/lib/node.js:126:14)
    at require.extensions.(anonymous function) (node_modules/babel-register/lib/node.js:136:7)
    at extensions.(anonymous function) (node_modules/require-precompiled/index.js:16:3)
    at Object.require.extensions.(anonymous function) [as .js] (node_modules/ava/lib/test-worker.js:89:3)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (client/front/Sidebar/index.js:6:19)
    at Module._compile (module.js:413:34)
    at loader (node_modules/babel-register/lib/node.js:126:5)
    at require.extensions.(anonymous function) (node_modules/babel-register/lib/node.js:136:7)
    at extensions.(anonymous function) (node_modules/require-precompiled/index.js:16:3)
    at Object.require.extensions.(anonymous function) [as .js] (node_modules/ava/lib/test-worker.js:89:3)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (client/front/Front.test.js:5:1)
    at Module._compile (module.js:413:34)
    at extensions.(anonymous function) (node_modules/require-precompiled/index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] (node_modules/ava/lib/test-worker.js:89:3)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (node_modules/ava/lib/test-worker.js:93:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3
# client/front/Front.test.js exited with a non-zero exit code: 1
not ok 1 - client/front/Front.test.js exited with a non-zero exit code: 1

Generated Module not found with babel-register

Hi,

I am trying to use babel-register instead of defining the config in the babelrc

So I run babel-register like this

#!/usr/bin/env node

// babel register, yeah
require("babel-register")({
  "env": {
    "statinamic": {
      "plugins": [
        [
          "babel-plugin-webpack-loaders",
          {
            "config": require("path").join(
              __dirname, "webpack.config.babel.js"
            ),
            "verbose": true,
          },
        ],
      ],
    },
  },
})

require(process.argv[2]) // my script to run

I have a server (the script called with argv[2]) that run a dev server that

  • use webpack middleware, to build webpack for client
  • prerender the same code for development purpose (=> a isomorphic dev server).

The server start, the client code is correctly built, but when my prenrender start his job, I got a weird error like the generated file per your plugin was missing (the dist/.webpack.res.*).

ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js in /Users/MoOx/Sync/Development/statinamic/docs
    at /Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (/Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:726:13
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:52:16
    at done (/Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:241:17)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:44:16
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:723:17
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:167:37
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:127:10
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/DirectoryDescriptionFilePlugin.js:24:12)
    at Storage.finished (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at ReadFileContext.callback (/Users/MoOx/Sync/Development/statinamic/node_modules/graceful-fs/graceful-fs.js:78:16)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)
resolve file
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js.js doesn't exist
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js.json doesn't exist
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js doesn't exist
resolve directory
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js doesn't exist (directory default file)
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js/package.json doesn't exist (directory description file)
Error: /Users/MoOx/Sync/Development/statinamic/docs/web_modules/layouts/Page/index.js: Command failed: node /Users/MoOx/Sync/Development/statinamic/node_modules/webpack/bin/webpack.js /Users/MoOx/Sync/Development/statinamic/docs/web_modules/layouts/Page/index.css /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js --config /Users/MoOx/Sync/Development/statinamic/src/bin/webpack.config.babel.js --colors --bail
ModuleNotFoundError: Module not found: Error: Cannot resolve 'file' or 'directory' /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js in /Users/MoOx/Sync/Development/statinamic/docs
    at /Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (/Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:726:13
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:52:16
    at done (/Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:241:17)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:44:16
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:723:17
    at /Users/MoOx/Sync/Development/statinamic/node_modules/async/lib/async.js:167:37
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
    at onResolved (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:38:18)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:127:10
    at /Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:191:15
    at applyPluginsParallelBailResult.createInnerCallback.log (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/Resolver.js:110:4)
    at loggingCallbackWrapper (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/createInnerCallback.js:21:19)
    at /Users/MoOx/Sync/Development/statinamic/node_modules/tapable/lib/Tapable.js:134:6
    at Tapable.<anonymous> (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/DirectoryDescriptionFilePlugin.js:24:12)
    at Storage.finished (/Users/MoOx/Sync/Development/statinamic/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at ReadFileContext.callback (/Users/MoOx/Sync/Development/statinamic/node_modules/graceful-fs/graceful-fs.js:78:16)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)
resolve file
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js.js doesn't exist
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js.json doesn't exist
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js doesn't exist
resolve directory
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js doesn't exist (directory default file)
  /Users/MoOx/Sync/Development/statinamic/docs/dist/.webpack.res.1457337445196_826582.js/package.json doesn't exist (directory description file)

    at checkExecSyncError (child_process.js:469:13)
    at execSync (child_process.js:509:13)
    at exports.default (/Users/MoOx/Sync/Development/statinamic/docs/node_modules/babel-plugin-webpack-loaders/lib/runWebPackSync.js:41:51)
    at PluginPass.CallExpression (/Users/MoOx/Sync/Development/statinamic/docs/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:86:60)
    at newFn (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/visitors.js:293:19)
    at NodePath._call (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/path/context.js:75:18)
    at NodePath.call (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/context.js:156:16)
    at TraversalContext.visitSingle (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/context.js:113:19)
    at TraversalContext.visit (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/context.js:200:19)
    at Function.traverse.node (/Users/MoOx/Sync/Development/statinamic/node_modules/babel-traverse/lib/index.js:141:17)

Any idea?

Alias not being replaced

I have a webpack config like this:

{ ... alias: { mylib: path.resolve(__dirname, 'src'), }, ... }

and my module importing like this:

import MyComponent from 'mylib/my_component';

and the generated code:

var _my_component = require('mylib/my_component');

Does this plugin resolve the module path and replace it? I know that exists a plugin for that, babel-plugin-webpack-alias, but it doesnt work well.

Recursion in resolving

I am currently replacing some old node code build by webpack by your plugin and got this weird error
(I have no idea how to fix it as I am writing this).
I am seeing that your are using "enhanced-resolve", but I am also seeing that this module is unmaintained (per description https://github.com/webpack/enhanced-require at the top of the page).

The module that seems to create a recursion is the resolution of the "github" package, no idea why this one...

Any idea?

โฏโฏ BABEL_DISABLE_CACHE=1 npms

> putaindecode.io@ start /Users/MoOx/Sync/Development/putaindecode.io
> npm run statinamic --server --open --dev


> putaindecode.io@ statinamic /Users/MoOx/Sync/Development/putaindecode.io
> cross-env BABEL_ENV=statinamic DEBUG=statinamic:* babel-node scripts/build

/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-core/lib/transformation/file/index.js:585
      throw err;
      ^

Error: /Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors/index.js: Recursion in resolving
Stack:
  resolve: (/Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors) github
  parsed-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors) github module
  described-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors) github module
  raw-module: (/Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors) github
  module: (/Users/MoOx/Sync/Development/putaindecode.io/scripts/contributors) github
  resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules) ./github
  parsed-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules) ./github
  described-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules) ./github
  relative: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) 
  described-relative: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) 
  directory: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) 
  existing-directory: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) 
  resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) ./.
  parsed-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) ./.
  described-resolve: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) ./.
  relative: (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/github) 
    at Tapable.doResolve (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/Resolver.js:90:25)
    at Tapable.<anonymous> (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/JoinRequestPlugin.js:21:12)
    at next (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/tapable/lib/Tapable.js:117:14)
    at Tapable.<anonymous> (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:17:30)
    at Tapable.applyPluginsAsyncSeriesBailResult1 (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/tapable/lib/Tapable.js:119:13)
    at innerCallback (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/Resolver.js:123:19)
    at loggingCallbackWrapper (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/tapable/lib/Tapable.js:210:15
    at Tapable.<anonymous> (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/enhanced-resolve/lib/ConcordModulesPlugin.js:25:28)
    at Tapable.applyPluginsParallelBailResult1 (/Users/MoOx/Sync/Development/putaindecode.io/node_modules/babel-plugin-webpack-loaders/node_modules/tapable/lib/Tapable.js:215:14)
``

Quesiton: "ES" build for webpack 2 tree shaking compatibility

If I wanted to create an "ES" build of a library such that import/export statements are not transpiled (e.g., essentially the es2015 babel present without "transform-es2015-modules-commonjs"), is it still possible to use this plugin? I would want to do so in order to take advantage of new tree shaking functionality in webpack 2.

Where are the .js files?

After having a little problem with having to ommit the filename key from the output hash, I'm wondering why only the assets are being exported and not the compiled .js file. Am I missing something?

Failing with Babel 6.5 CLI

As soon as babel 6.5 was released, tests I've been running with no problem started to fail hard.

Example of the failed build: https://circleci.com/gh/nkbt/react-component-template/321

$(npm bin)/babel-node test | $(npm bin)/tap-xunit > ${CIRCLE_TEST_REPORTS}/test.xml && test ${PIPESTATUS[0]} -eq 0
/home/ubuntu/react-component-template/node_modules/babel-core/lib/transformation/file/index.js:585
      throw err;
      ^

TypeError: /home/ubuntu/react-component-template/src/example/App.js: Cannot read property 'start' of undefined
    at /home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:29:19
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:99:30)
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:101:19)
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:101:19)
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:101:19)
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:101:19)
    at Whitespace._findToken (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:101:19)
    at Whitespace.getNewlinesBefore (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/whitespace.js:28:22)
    at CodeGenerator._printNewline (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:271:33)
    at CodeGenerator.print (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:85:10)
    at CodeGenerator.printJoin (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:193:12)
    at CodeGenerator.printList (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:258:17)
    at CodeGenerator.ObjectExpression (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/generators/types.js:48:10)
    at CodeGenerator._print (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:155:17)
    at CodeGenerator.print (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/printer.js:91:10)

at CodeGenerator.VariableDeclarator (/home/ubuntu/react-component-template/node_modules/babel-generator/lib/generators/statements.js:306:10) $(npm bin)/babel-node test | $(npm bin)/tap-xunit > ${CIRCLE_TEST_REPORTS}/test.xml && test ${PIPESTATUS[0]} -eq 0 returned exit code 1

When I commented out inclusion of App.js which itself includes App.css - everything is back to normal.

import test from 'tape';
//import App from '../../src/example/App';


test('App', t => {
//  t.ok(App instanceof Function, 'should be function');
  t.end();
});

App.js -> https://github.com/nkbt/react-component-template/blob/master/src/example/App.js

.babelrc -> https://github.com/nkbt/react-component-template/blob/master/.babelrc

Feel free to close the ticket if it is too specific case. I just wanted to check if I am alone with it.

Will debug a bit later

ava and "Unexpected token import"

Hi,

I am trying to run tests with AVA and your plugin.
At the first place, it wasn't working (error below). I rm -rf node_modules, then tried again and it was working (tests on jsx and react were failing as expected). No idea why, I changed a string in my file, and got this error:

Uncaught Exception: /Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/web_modules/Button/__tests__/index.js
  SyntaxError: /Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/web_modules/Button/__tests__/index.js: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at localInteropRequire (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:211:13)
    at PluginPass.CallExpression (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-plugin-webpack-loaders/lib/plugin.js:41:135)
    at newFn (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (/Users/MoOx/Sync/Development/_clients/one2team/o3-mobile/node_modules/babel-traverse/lib/context.js:184:19)

I reverted my changes but same problem.

Note that I run with the following command (I just pasted interesting part)

{
  "scripts": {
    "ava": "CONFIG=$(pwd)/webpack.config.test.babel.js BABEL_DISABLE_CACHE=1 NODE_ENV=test ava",
    "test": "npm run lint && npm run ava"
  },
  "babel": {
    "presets": [
      "babel-preset-react",
      "babel-preset-es2015",
      "babel-preset-stage-1"
    ],
    "env": {
      "production": {
        "plugins": [
          "babel-plugin-react-remove-prop-types"
        ]
      },
      "test": {
        "plugins": [
          [
            "babel-plugin-webpack-loaders",
            {
              "config": "${CONFIG}",
              "verbose": false
            }
          ]
        ]
      }
    }
  },
  "ava": {
    "files": [
      "web_modules/**/__tests__/*.js"
    ],
    "failFast": true,
    "verbose": true,
    "require": [
      "babel-register"
    ],
    "babel": "inherit"
  },

I cannot share my webpack config as it's very messy and private, just be sure that I use this

// import normal config
import webpackConfig from "./webpack.config.babel.js"

export default {
  ...webpackConfig,

  // babel-plugin-webpack-loaders requirements
  entry: undefined,
  output: {
    libraryTarget: "commonjs2",
  },
}

Webpack 2.x compatibility

So far as I can tell, in Webpack 2.x, --colors is no longer a valid CLI option. --color is now the supported option. Running this plugin using Webpack 2.1.0-beta.4 (current as of today) produces a huge console error, though the meat of it is: Unknown argument: colors.

Changing the option to --color in lib/runWebPackSync.js fixes the issue, though I'm assuming would break compatibility with Webpack 1.x.

Error on Import external css library

Based on minimal example, I npm install normalize.css and added import "normalize.css/normalize.css" to example.js.
I am getting following error on npm run start:
You can't import file normalize.css/normalize.css to a module scope.
Any idea how to fix this?

one instance of the plugin

Hi

Is it possible to create just one instance of the webpack ?
It is working "instance per compiled module" in this moment. But you are not able to use plugins like extract-text-webpack-plugin with parameter allChunks.
Maybe it is by design. I do not know.

change css file issue

Hi

I have two files index.js and index.css (index.js requires index.css)
When I change index.css it will use old version.
I need to change index.js too if I want to get latest noncached index.css.
Anyway thank you for this great package :)

TypeError: ..... invalid data

I was trying to use this on my project and I kept getting stuff like:

ERROR in ./components/button/Button.jsx Module build failed: TypeError: C:/[some directory paths]/components/button/Button.jsx: invalid data

I thought perhaps it was just the complexities of my app, so I decided to clone down this repo and run npm run example-build, and I get the same error:

TypeError: examples/myCoolLibrary/myCoolLibrary.js: invalid data

Here is a screenshot:
typerror

I am on a Windows 7 machine, if that makes any difference. I'm not quite sure where to start on this, but I'll keep digging to see if I can find a solution/submit a PR. If you have any insight/advice that might be helpful, would be appreciated.

Support module-path

I don't like the relative behavior of the require of node, hence, I'm using

// Set the /src folder as root
const path = require('path');
require('app-module-path').addPath(path.join(__dirname, ''));

to change the root of my import to the /src folder of my project.

In order to make this plugin works, I had to change this line with:

filePath = '/Users/oliviertassinari/MyProject/src/' + filePath;

Any idea of a better solution so that I don't have to do this ugly fix ๐Ÿ™ˆ?

CSS Loaders - compile to the directory being loaded from?

My application structure is as follows

โ”œโ”€โ”€ js
โ”‚ย ย  โ”œโ”€โ”€ App.js
โ”‚ย ย  โ”œโ”€โ”€ Routes.js
โ”‚ย ย  โ”œโ”€โ”€ components
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ Header
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ Header.js
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ Header.scss

I have tried all the examples, but neither get me quite to where i want to be.

This example got me the closest (using a .css file)
https://github.com/istarkov/babel-plugin-webpack-loaders/blob/master/examples_webpack_configs/run.webpack.config.js

Can the styles be returned in-place (in a style elem) and not output to a file?

So with the above example, the console.log of the css file returned the class names, but i could not find the styles themselves. I basically want it so that when I require('./Header.css') or require('./Header.scss') (in Header.js) I can use the class names and the styles will be included on the page in a <style> tag.

Is that possible with this plugin?

Thanks a lot!

webpack@2 support

webpack 2 supports a function as config (see https://gist.github.com/sokra/27b24881210b56bbaff7#configuration).
This is currently breaking this plugin.

Uncaught Exception: .../web_modules/Logo/__tests__/index.js
  TypeError: .../web_modules/Logo/__tests__/index.js: Cannot read property 'loaders' of undefined
    at PluginPass.CallExpression (.../node_modules/babel-plugin-webpack-loaders/lib/plugin.js:81:26)
    at newFn (.../node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (.../node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (.../node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:184:19)
    at Function.traverse.node (.../node_modules/babel-core/node_modules/babel-traverse/lib/index.js:135:17)
    at NodePath.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:103:22)
    at TraversalContext.visitQueue (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitMultiple (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:110:17)
    at TraversalContext.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:182:19)
    at Function.traverse.node (.../node_modules/babel-core/node_modules/babel-traverse/lib/index.js:135:17)
    at NodePath.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:103:22)
    at TraversalContext.visitQueue (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:152:16)
    at TraversalContext.visitSingle (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:115:19)
    at TraversalContext.visit (.../node_modules/babel-core/node_modules/babel-traverse/lib/context.js:184:19)
    at Function.traverse.node (.../node_modules/babel-core/node_modules/babel-traverse/lib/index.js:135:17)
    at Object.traverse [as default] (.../node_modules/babel-core/node_modules/babel-traverse/lib/index.js:69:12)
    at .../node_modules/babel-core/lib/transformation/file/index.js:513:33
    at Array.forEach (native)

I will try to make a PR.

Ignore files which is not in loaders

babel-plugin-webpack-loaders is cool.

In v0.3, babel-plugin-webpack-loaders will parse the file which is not in loaders.
image
Not sure this is necessary.

In v0.2, there is no the behavior.

It is looks because of the enhanced-resolve@2

Missing documentation or context about being usable for backend purposes only

Hi, I am trying to use this plugin as a way to resolve webpack loaders on a per file basis so that I can inline some stylesheets in my library when loaded via commonjs.

I have an ES6 frontend library https://github.com/algolia/places that I want people to be able to require() via browserify/webpack. I have some SVG icons and CSS files, SVG raw-loader works perfectly but just trying to use style-loader and css-loader fails. I just want the main JavaScript file to inline the style-loader code.

The output is empty as soon as I try to use style-loader and css-loader.

Here's an example project: https://github.com/vvo/babel-plugin-webpack-loaders-test

Reading the readme I can see that this library is mainly for BACKEND purposes but I am failing at understanding why exactly?

Do you think I can achieve somehow what I am looking for? Maybe I should split the css-loader from the style-loader usage and insert the CSS myself after getting its content in a variable? Thanks.

v0.3.0 Issue

I have tried to upgrade to v0.3.0 however that's no longer working.
My source code looks like (src/Main/Product.jsx):

...

import polyglot from 'polyglot'; // Located in src/polyglot.js

// import imageIcon from 'Main/Product/icon.png'; (I can't make it work)
import imageIcon from './icon.png';

....

Here is the stack trace:

/Users/oliviertassinari/SplitMe/node_modules/babel-core/lib/transformation/file/index.js:585
      throw err;
      ^

Error: /Users/oliviertassinari/SplitMe/src/Main/Product/Footer.jsx: Can't resolve 'polyglot' in '/Users/oliviertassinari/SplitMe/src/Main/Product'
    at onResolved (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/Resolver.js:64:16)
    at loggingCallbackWrapper (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at afterInnerCallback (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/Resolver.js:136:10)
    at loggingCallbackWrapper (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at Tapable.applyPluginsAsyncSeriesBailResult1 (/Users/oliviertassinari/SplitMe/node_modules/tapable/lib/Tapable.js:108:46)
    at innerCallback (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/Resolver.js:123:19)
    at loggingCallbackWrapper (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at /Users/oliviertassinari/SplitMe/node_modules/tapable/lib/Tapable.js:210:15
    at innerCallback (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/Resolver.js:121:11)
    at loggingCallbackWrapper (/Users/oliviertassinari/SplitMe/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)

Error: provided an invalid property of "config"

BABEL_DISABLE_CACHE=1 NODE_ENV=test ./node_modules/.bin/babel-node file.js

Produces:

Error: Plugin 1 specified in "/home/me/work/project/.babelrc.env.test" provided an invalid property of "config"
    at Plugin.init (/home/me/work/project/node_modules/babel-core/lib/transformation/plugin.js:138:13)

.babelrc

{
  "presets": [
    "react",
    "es2015"
  ],
  "plugins": [
    "transform-object-rest-spread",
    "syntax-trailing-function-commas",
    "transform-export-extensions"
  ],
  "env": {
    "test": {
      "plugins": [
        "babel-plugin-webpack-loaders",
        {
          "config": "./path/to/webpack.config.test.js",
          "verbose": false
        }
      ]
    }
  }
}

Versions:

    "babel-cli": "^6.10.1",
    "babel-loader": "^6.2.2",
    "babel-plugin-syntax-trailing-function-commas": "^6.5.0",
    "babel-plugin-transform-export-extensions": "^6.5.0",
    "babel-plugin-transform-object-rest-spread": "^6.6.5",
    "babel-plugin-webpack-loaders": "^0.7.0",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "babel-register": "^6.9.0",

Using it with react universal and css-modules

Would it be possible to somehow generate the same classnames on the client and on the server?
Now I have an issue that client webpack generates different classnames then server with babel-plugin-webpack-loaders
Cheers

Plugin hangs without errors, seemly does nothing

Afaics I did everything required to use this plugin. However when I do npm run start, it display the text below and seemingly does nothing. It never stops and no errors appear.

babel-plugin-webpack-loader:
js and jsx files in loaders is unsupported by webpack-loader plugin.
all babel settings in loader will be skipped

Even when I set verbose to true in babel.rc, it gives me nothing.

Alternative way to specify the babel env

The current method is not really "cross platform" in the way you need a different command on windows to set an env variable.
Do you think we could found another (more cross platform) way to setup the babel env? Maybe using babel-register with option?

Infinite loop with json-loader

Hi,

First of all, thanks for this project. I was thinking about it everyday for some weeks and before starting working on it, I found this one.

I am currently trying it on a project that where using webpack to build a node script (which is kind of annoying). I am facing an issue.

My configuration is having a section for json on client side

    {
        test: /\.json$/,
        loader: "json-loader",
      },

This part create (not sure why) an infinite process, stuck where the required json is called.
Removing it fixed the thing.
I can add this to my config only when used for client. That's a solution.

But at the same time, I am wondering if some loader should not be blacklisted.
Like babel-loader. For client build, babel-loader might make sense. But in the context of this project, (which is "run your code via babel), babel-loader doesn't make any sense, like json-loader. Maybe we should blacklist those?

Pick wrong ast node when results with dependences

It is be mentioned in #14

/Users/MoOx/Sync/Development/statinamic/docs/web_modules/Header/index.js:27
var _statinamicText = deprecated;
                      ^
ReferenceError: deprecated is not defined

For now, the tested loaders in example, css-loader, file-loader, png-loader, will return a simple module.

modules.exports  = webpackBootstrap([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
        module.exports = __webpack_require__.p +"fc2bafa27d25941c90e00aadcfd76661.svg";
/***/ }
/******/ ])

So they will work well.

But in some loader will transform code with other modules. it will be broken, like react-svg-loader and mine https://github.com/morlay/svg2jsx

the result will be

modules.exports  = webpackBootstrap([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
        var  React =  __webpack_require__(1);
        module.exports = React.createElement('div');
/***/ }๏ผŒ
/* 1 */
/***/ function(module, exports, __webpack_require__) {

/***/ }
/**and others */
/******/ ])

Then babel-plugin-webpack-loaders will pick the last one (re-assign until the last,
https://github.com/istarkov/babel-plugin-webpack-loaders/blob/master/src/plugin.js#L37),
This is why there is a deprecated in the issue at the beginning.

And by the way, should we need to package all dependences ?

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.