Skip to content

Can filename/chunkFilename support function type ? #67

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

Closed
Fuji-sunny opened this issue Mar 29, 2018 · 19 comments
Closed

Can filename/chunkFilename support function type ? #67

Fuji-sunny opened this issue Mar 29, 2018 · 19 comments

Comments

@Fuji-sunny
Copy link

Fuji-sunny commented Mar 29, 2018

Much thanks for this project!

Here my project is a multi-page project, which means that I need my dist directory to be like this:
dist/
|---a/
| |---js/
| | |---a.js
| |---css/
| | |---a.css
| |---html/
| | |---a.html
|---b/
| |---js/
| | |---b.js
| |---css/
| | |---b.css
| |---html/
| | |---b.html

The entry point is 'xxx/js/xxx.js' so the [filename] in mini-css-extract-plugin is 'xxx/js/xxx'.
After webpack build my css files are in the [xxx/js/] directory, not my expectation [xxx/css/] directory.

In extract-text-webpack-plugin [filename] can be a function type and provide a getPath function as its arguments.
Can mini-css-extract-plugin's [filename] support function type like this ?
Or any other suggestion about the above implementation ?

@sokra
Copy link
Member

sokra commented Mar 29, 2018

Send a PR to allow function for filename

@lcxfs1991
Copy link

@sokra Are you going to submit a PR recently?

@alexander-akait
Copy link
Member

Feel free to send PR 👍

@lcxfs1991
Copy link

@evilebottnawi Haha. Actually I send the PR for extract-text-webpack-plugin before. Let me think of it.

@lcxfs1991
Copy link

@evilebottnawi @sokra

I look into the source code today and find that a bit difficult to just pass a function to filename option.

Any suggestions for what we can do?

@alexander-akait
Copy link
Member

alexander-akait commented Apr 7, 2018

@lcxfs1991 https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/index.js#L103 just add your code before, check on function and if function run it and save in filename

@lcxfs1991
Copy link

@evilebottnawi Are you at Gitter? Let me discuss with you there.

@alexander-akait
Copy link
Member

@lcxfs1991 give me link

@lcxfs1991
Copy link

@davityavryan
Copy link

Hi guys,
Any news regarding this change?

@alexander-akait
Copy link
Member

PR welcome

@Fuji-sunny
Copy link
Author

Is there any update with this issue?

@glen-84
Copy link

glen-84 commented Jun 16, 2018

@Fuji-sunny See #145.

@domonique-ncino
Copy link

It will be great if this gets merged in

@rohmann
Copy link

rohmann commented Mar 22, 2019

It looks like you can set filename to a function if chunkFilename is also set. For example:

new MiniCssExtractPlugin({
      filename: ({ chunk }) => `dist/${entries[chunk.name].dest}`,
      chunkFilename: '[id]'
    })

Unless I'm missing something, maybe this just needs a bit of documentation and better error handling?

@ghost
Copy link

ghost commented Aug 13, 2019

Try to use moduleFilename. You don't need to set chunkFilename .

new MiniCssExtractPlugin({
  moduleFilename: (chunk) => `dist/${chunk.name}.css`
}),

This works fine :)

@silkfire
Copy link

silkfire commented Dec 18, 2019

@evilebottnawi The moduleFilename option doesn't seem to work when using runtimeChunk. Why is that?

ttys3 added a commit to ttys3/hugo-theme-terminal that referenced this issue May 1, 2020
@alexander-akait alexander-akait changed the title Can filename support function type ? Can filename/chunkFilename support function type ? Aug 13, 2020
@alexander-akait
Copy link
Member

Fixed #602, chunkFilename as Function available on for webpack@5, webpack@5 release will be 2020-10-10

@alexander-akait
Copy link
Member

moduleFilename was removed in favor filename/chunkFilename

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

Successfully merging a pull request may close this issue.

10 participants