This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 512
refractor filename modify logic #423
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
16ada23
add filename filter to modify path and filename
lcxfs1991 fa1a429
fix README
lcxfs1991 1411ae0
add temp repo README
lcxfs1991 a5729c7
add filename filter
lcxfs1991 839687b
upgrade to 2.x
lcxfs1991 454e0b9
improve readme
lcxfs1991 e68b4d9
resolve conflict
lcxfs1991 bf8a6f9
Merge branch 'webpack-contrib-master'
lcxfs1991 e810aac
refractor filename modify logic
lcxfs1991 41764e9
refractor filename modify logic
lcxfs1991 1e90af9
fix typo
lcxfs1991 c525c1f
refractor filename modify logic
lcxfs1991 4356fe5
increate test coverage rate
lcxfs1991 e6c6624
Merge branch 'master' into master
lcxfs1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ new ExtractTextPlugin(options: filename | object) | |
|Name|Type|Description| | ||
|:--:|:--:|:----------| | ||
|**`id`**|`{String}`|Unique ident for this plugin instance. (For advanced usage only, by default automatically generated)| | ||
|**`filename`**|`{String}`|Name of the result file. May contain `[name]`, `[id]` and `[contenthash]`| | ||
|**`filename`**|`{String|Object}`|Name of the result file. May contain `[name]`, `[id]` and `[contenthash]`| | ||
|**`allChunks`**|`{Boolean}`|Extract from all additional chunks too (by default it extracts only from the initial chunk(s))| | ||
|**`disable`**|`{Boolean}`|Disables the plugin| | ||
|**`ignoreOrder`**|`{Boolean}`|Disables order check (useful for CSS Modules!), `false` by default| | ||
|
@@ -155,6 +155,29 @@ module.exports = { | |
} | ||
``` | ||
|
||
### Modify filename | ||
|
||
`filename` paramter could be `Object`. It accepts `format` and `modify` callback as attributes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /s/paramter/parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does that mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a typo. |
||
In the following config, before `modify` callback is called, the css path would be `css/js/a.css`. | ||
After `modify` callback, it is transformed to `css/a.css`. | ||
|
||
```js | ||
entry: { | ||
'js/a': "./a" | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin({ | ||
filename: { | ||
format: 'css/[name].css', | ||
modify: (filename) => { | ||
return filename.replace('css/js', 'css'); | ||
} | ||
}, | ||
allChunks: true | ||
}) | ||
] | ||
``` | ||
|
||
<h2 align="center">Maintainer</h2> | ||
|
||
<table> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require.ensure([], function() { | ||
require("./a.txt"); | ||
require("./b.txt"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require.ensure([], function() { | ||
require("./a.txt"); | ||
require("./c.txt"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a | ||
b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
a | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var ExtractTextPlugin = require("../../../"); | ||
module.exports = { | ||
entry: { | ||
'js/a': "./a", | ||
'js/b': "./b" | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin({ | ||
filename: { | ||
format: 'txt/[name].txt', | ||
modify: (filename) => { | ||
return filename.replace('txt/js', 'txt'); | ||
} | ||
}, | ||
allChunks: true | ||
}) | ||
] | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could accept a function directly instead of an object. The function would return a filename and allow you modify it. Simpler API/design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also have to pass filename format like
[name].css
. Is is possible to do that via afunction
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return a pattern and it will work like before. You can do
filename: file => '[name].css'
in this design too. And access to thefile
parameter gives you flexibility for custom logic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add
js/a
as the entry key, webpack will replace[name]
withcss/js/a
and it leaves no room for developers to do the following action:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can try my test case:
test/cases/multiple-entries-filename/webpack.config.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It's that
compilation.getPath
which is the problem. Basicallymodify
triggers after that.The design could be inverted like this:
That
getPath
would runcompilation.getPath
with all its parameters and provide the hook that would give you maximum amount of control. Now you could manipulatefilename
before and after placeholders get applied while keeping the API surface minimal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose
getPath
is cool too.let me retune it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll have a closer look in a bit. 👍