forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack-eol-plugin.js
More file actions
38 lines (33 loc) · 1.31 KB
/
webpack-eol-plugin.js
File metadata and controls
38 lines (33 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const eol = require("eol");
const sources = require("webpack-sources");
const pluginName = 'WebpackEolPlugin';
/**
* This plugin forces outputs from webpack to use CRLF instead of OS native.
* Fixes issues with git thinking files are different when they are not.
*/
class WebpackEolPlugin {
apply(compilation) {
compilation.hooks.compilation.tap(pluginName, (compilation) => {
compilation.hooks.afterOptimizeAssets.tap(
{
name: pluginName,
stage: compilation.PROCESS_ASSETS_STAGE_DEV_TOOL
},
(assets) => {
for (let i in assets) {
if (i.endsWith('.js.map')) {
continue;
}
const asset = compilation.getAsset(i); // <- standardized version of asset object
const source = asset.source.source(); // <- standardized way of getting asset source
// standardized way of updating asset source
compilation.updateAsset(
i,
new sources.RawSource(eol.crlf(source))
);
}
});
});
}
}
module.exports = WebpackEolPlugin;