Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Emit files relative to entries #153

Closed
dnutels opened this issue Apr 20, 2017 · 3 comments
Closed

Emit files relative to entries #153

dnutels opened this issue Apr 20, 2017 · 3 comments

Comments

@dnutels
Copy link

dnutels commented Apr 20, 2017

Do you want to request a feature or report a bug?

Feature

What is the current behavior?

Consider dynamically created Webpack config entries:

...
compiler({
    target: 'node',
    entry: createEntries(...),
    output: {
        filename: '[name]/index.js',
        path: 'dist/'
    },
    module: {
        rules: [
            {
                test: /assets\/js\/.*\.js$/,
                loader: 'file-loader',
                options: {
                    ???
                    name: '[name].[ext]'
                }
            },
        }
    },
    ...
});

where the source folder structure:

src/components/comp-a/
    assets/js/index.js
    index.js
    package.json
src/components/comp-b/
    assets/js/index.js
    index.js
    package.json

and the resulting entry (the one calculated using createEntries function) is:

entry: {
    'comp-a-0.0.1': 'full/path/to/src/components/comp-a/',
    'path-b-0.0.2': 'full/path/to/src/components/comp-b/'
}    

In all cases, where applicable, consider the paths in the above examples to be resolved properly, using path and such. They were omitted for brevity. Also 0.0.1 and 0.0.2 are versions extracted from corresponding package.json file that can be seen in source folder structure above.

As a result of the build configuration above, the following files are created:

dist/comp-a-0.0.1/
    index.js
dist/comp-b-0.0.2/
    index.js

What is the expected behavior?

I would have expected an ability to receive the following:

dist/comp-a-0.0.1/
    assets/js/index.js
    index.js
dist/comp-b-0.0.2/
    assets/js/index.js
    index.js

If this is a feature request, what is motivation or use case for changing the behavior?

Reasoning: in my case, I build node-targeted artifacts (the dynamic entries) that may carry static assets (those assets/js/index.js files). I want to be able to emit these files relative to the entry.

They are not going to be consumed using that path (so things like publicPath runtime adjustments are irrelevant) and are for organizational purposes (these are then published to NPM and such).

Currently, these are always relative to some single entity -- dist/, publicPath and such. outputPath doesn't help either, due to dynamically created entries and difference between source folder name and the corresponding entry name.

Please mention other relevant information such as your webpack version, Node.js version and Operating System.

webpack 2.4.1
file-loader 0.11.1
Node 7.9.0

@alexander-akait
Copy link
Member

@dnutels Seems it is out of scope of file-loader. Why don't use just CopyWebpackPlugin? If you want to handle js files using babel and other stuff, you can use multi-compiler. First compile dist/comp-a-0.0.1/index.js and copy from src/components/comp-a/assets/js/index.js to dist/components/comp-a/assets/js/index.js, second run babel-loader and other stuff. Thanks!

@janko-sokolovic
Copy link

Hi, @dnutels

Did you find a workaround or a proper solution to your problem? I'm having the same 'issue'/request :)

@alexander-akait
Copy link
Member

Thanks everyone! Duplicate #114. Feel free to PR

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

No branches or pull requests

3 participants