Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using es6-loader with non-js loaders. #6

Open
iamdustan opened this issue Jun 3, 2014 · 2 comments
Open

Using es6-loader with non-js loaders. #6

iamdustan opened this issue Jun 3, 2014 · 2 comments

Comments

@iamdustan
Copy link

I spent too many cycles trying to figure out why my require('css!style!stylus!./module.styl'); was not working this morning. Then I remembered that JS file was being compiled by the es6-loader and the require call was probably being transformed in some way there.

Is there any clean way to use the es6-loader without smashing all require calls for webpack?

@shama
Copy link
Owner

shama commented Jun 3, 2014

If you're using the loader inline, it is import bamboo from 'es6!./module.js'; or from non-es6, require('es6!./module.js').

Or if you want it cleaner, add the following to your webpack config:

module: {
  loaders: [
    { test: /\.js$/, loader: 'es6-loader' }
  ]
}

and just require('./module.js')


Loaders are applied in the order you place them. So for your example, require('css!style!stylus!./module.styl')... it will transform stylus to css, apply the css to the page and then convert to css? Probably not what you're intending.

You probably want one of these:

  • require('style!raw!stylus!./module.styl') Convert the stylus to css, apply the raw CSS to the page.
  • require('style!css!stylus!./module.styl') Convert the stylus to css, apply additional resolutions with the css-loader and then apply to the page.

Leave off the style! if you don't want to apply to the page but want to return the compiled CSS. All of these can be moved into the webpack config if you want cleaner require calls as well.

@iamdustan
Copy link
Author

Here is what I had that was failing.

main.js

var css = require('./styles.styl');
document.body.classList.remove('is-loading');

import { Leaderboard, Vote, UploadManager } from './app';
new Leaderboard();
new Vote();
new UploadManager();

webpack.config.js

module.exports = {
  context: __dirname + '/source',
  entry: './main.js',
  output: {
    path: __dirname + '/public',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' },
      { test: /\.js$/, loader: 'es6-loader' },
    ]
  },
};

I had to change the es6-loader to ignore the initial file to get the css require to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants