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

Overriding default config for file-loader and url-loader #80

Closed
viktor-nikolaev opened this issue Jan 13, 2017 · 21 comments
Closed

Overriding default config for file-loader and url-loader #80

viktor-nikolaev opened this issue Jan 13, 2017 · 21 comments

Comments

@viktor-nikolaev
Copy link

I have a question. This configuration for my .less files

module.exports = createConfig([
setContext(stylesDirectory),
entryPoint({
    "style-day-mode": "style-day-mode",
    "style-night-mode": "style-night-mode"
}),
setOutput({
    path: helpers.root("./wwwroot/styles"),
    filename: "[name].js"
}),
addPlugins([
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(true),
    new ExtractTextPlugin("[name].css", {allChunks: true})
]),
customConfig({
    resolve: {
        extensions: ["", ".less"],
        modulesDirectories: ["node_modules", stylesDirectory]
    },
    module: {
        loaders: [
            {
                test: /\.less$/,
                loader: ExtractTextPlugin.extract("css!less")
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                include: /node_modules/,
                loader: "file-loader?name=../fonts/[name].[ext]"
            },
            {
                test: /\.(gif|png)$/,
                include: /ReportWriter/,
                loader: "url-loader?name=../images/[name].[ext]&limit=10240"
            }
        ]
    },
})
]);

however it's conflicting with default @webpack-blocks config created in createBaseConfig.
Is there any way to override the behavior?

@andywer
Copy link
Owner

andywer commented Jan 13, 2017

Hey @Veikedo.

That's a rather tricky one. If it's really the default config it is conflicting with we could do the following:

You could try monkey-patching the node_modules/@webpack-blocks/webpack/index.js file to see if that solves your issue:

Before:

function createConfig (configSetters) {
  return core.createConfig(webpack, [ createBaseConfig ].concat(configSetters))
}

After:

function createConfig (configSetters) {
  return core.createConfig(webpack, configSetters)
}

We could provide a createConfig.vanilla() method that does the same with the next release (I was going to release today anyway, because of another change).

Could you try that and confirm that it works?

@eXon I always feared that this default config might cause trouble one day, but hoped it was so generic that it would be ok... What do you think about createConfig.vanilla()?

@viktor-nikolaev
Copy link
Author

viktor-nikolaev commented Jan 13, 2017

Hi @andywer
yes, monkey patching solves the issue. I just commented the default loaders in createBaseConfig function.
on the image is what the conflict does. url-loader ignores the limit I set in my config, and file-loader ignores the path where I store assets
image

@viktor-nikolaev
Copy link
Author

btw as far as you are going to release, could you please add text/x-less to defaultFileTypes.js? so I can use yours great extractTextPlugin without modifications

@andywer
Copy link
Owner

andywer commented Jan 13, 2017

Sure :)

I don't know if you need the less-loader more than once and if you would like to contribute code, but it would certainly be cool if you would open a PR introducing a Less block 😊

@andywer
Copy link
Owner

andywer commented Jan 13, 2017

Please try @webpack-blocks/webpack@0.4.0-rc.1 and use createConfig.vanilla() instead of createConfig().

Keeping it open until you confirm that it works for you 😉

@andywer andywer reopened this Jan 13, 2017
@viktor-nikolaev
Copy link
Author

viktor-nikolaev commented Jan 13, 2017

@andywer thank you!

However you could not just omit resolve.extensions, without it the build fails with an error in webpack's core. So the function should be something like that

function createVanillaConfig (configSetters) {
  function initial() {
    return {
        resolve: {
            extensions: [ '']
        }
    }
  };

  return core.createConfig(webpack, [ initial ].concat(configSetters))
}

@andywer
Copy link
Owner

andywer commented Jan 13, 2017

@Veikedo Thanks for the quick feedback! Now the question is... How vanilla should the "vanilla config" be... 😅

  1. If you opt-in for the vanilla config this is now your thing to care about.
  2. Vanilla config providing default resolve.extensions is still ok

I think I've got to sleep a night about that...
@eXon Any thoughts?

@viktor-nikolaev
Copy link
Author

@andywer here is my workaround for that moment

const monkeyPath = () => ({
    resolve: {
        extensions: ['']
    }
});

module.exports = createConfig.vanilla([
    monkeyPath,
....

without the patch it fails as in the picture
image

@viktor-nikolaev
Copy link
Author

viktor-nikolaev commented Jan 13, 2017

interesting that moving my customConfig (which has resolve.extensions) at the top does not solve the issue

@andywer
Copy link
Owner

andywer commented Jan 13, 2017

interesting that moving my customConfig (which has resolve.extensions) at the top does not solve the issue

That seems odd! Are you sure there is not another problem? (Maybe compare the two generated configs)

resolve: { extensions: [ '' ] }

Ahhh... I didn't recognize that setting resolve.extensions to [''] already fixes the issue 😉

@andywer
Copy link
Owner

andywer commented Jan 14, 2017

PS: Does an empty array as resolve.extensions work, too?

@viktor-nikolaev
Copy link
Author

viktor-nikolaev commented Jan 15, 2017

@andywer no it does not. At least empty extension must be present

@andywer
Copy link
Owner

andywer commented Jan 16, 2017

Yeah, I read the resolve.extensions documentation and I think the whole problem boils down to:

If you configure any kind of custom resolve.extensions webpack will drop the default extensions and just use the ones you pass. And the empty string is by default not part of the resolve.extensions. I assume you import/require files using their extension (require('./foo.js') as opposed to require('./foo')), that's why you cannot just stick to the webpack defaults (setting no resolve.extensions at all).

Bottom line: I think the vanilla config should really be vanilla (that means no resolve.extensions either), because otherwise we might need to add another really-vanilla config in future. I suggest you use the vanilla config and set the resolve.extensions manually for now, but resolve.extensions including '' should become part of #60 :)

Does that sound ok to you?

@viktor-nikolaev
Copy link
Author

viktor-nikolaev commented Jan 16, 2017

@andywer I just found that extract-text block assumes that module.loaders section exists (see this line). So it fails when using current implementation of createVanillaConfig.

I understand your concerns. However, in my opinion there is nothing bad in providing a skeleton of webpack.config, ie with empty resolve.extensions, empty loaders section and so on.

Also an empty extension '' is included by default in webpack2

@andywer
Copy link
Owner

andywer commented Jan 16, 2017

I just found that extract-text block assumes that module.loaders section exists (see this line). So it fails when using current implementation of createVanillaConfig.

Good point! There is nothing wrong with providing an empty loaders array I think. Will change that, thanks :)

I understand your concerns. However, in my opinion there is nothing bad in providing a skeleton of webpack.config, ie with empty resolve.extensions, empty loaders section and so on.

The problem is that an empty resolve.extensions will also disable webpack's default extensions. I would agree if setting an empty array would not change webpack's behavior there...

Also an empty extension '' is included by default in webpack2

Ahh. Ok, then they did not update the docs yet...

@viktor-nikolaev
Copy link
Author

Ahh. Ok, then they did not update the docs yet...

@andywer it's in the migrating guide https://webpack.js.org/guides/migrating/#resolve-extensions

@andywer andywer added this to the 0.4.0 milestone Jan 18, 2017
@andywer
Copy link
Owner

andywer commented Jan 21, 2017

@Veikedo Can you confirm that adding an empty module.loaders array fixes the problem (like in #95)? I would close the issue if that works.

Or do you need me to publish another 0.4.0-rc* version?

@viktor-nikolaev
Copy link
Author

@andywer unfortunately can't check till next week. I think, it should work fine

@andywer
Copy link
Owner

andywer commented Feb 13, 2017

@Veikedo Any news? 😉

@viktor-nikolaev
Copy link
Author

@andywer oh, sorry. Yes, everything is working.
Thank you!

@andywer
Copy link
Owner

andywer commented Feb 14, 2017

Awesome! :)

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

No branches or pull requests

2 participants