You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This plugin will omit the JS files, for CSS only dependencies, that become obsolete once extract-text-plugin extracts all inlined CSS into its own .css file
4
+
5
+
## Rationale
6
+
7
+
In some cases, you may want to organize some of your CSS dependencies into single files or entry arrays within Webpack. Extract-text-plugin extracts the CSS into its own .css file, but Webpack will still generate a js file that will never be needed. This plugin will omit these types of files before Webpack begins it's emitting step. This plugin is especially useful for Webpack bundles that use a hash in the the filename, as these change on every compilation.
8
+
9
+
Example as a file
10
+
```js
11
+
// styles.js
12
+
require('a.css');
13
+
require('b.css');
14
+
15
+
// webpack.config.js
16
+
module.exports= {
17
+
entry: {
18
+
'common.styles':'styles.js'
19
+
}
20
+
}
21
+
// Webpack Output:
22
+
// common.styles.js (Not Needed)
23
+
// common.styles.css
24
+
```
25
+
NOTE: CSS dependencies in a JS file are 1 level deep. It will not recursively check for dependencies that are only CSS when requiring additional JS files.
NOTE: [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin"ExtractTextPlugin") is a Peer Dependency. You will need to configure that as you normally would in your webpack.config.js
59
+
60
+
## Options
61
+
```js
62
+
newOmitJSforCSSPlugin(options: object)
63
+
```
64
+
|Name|Type|Default|Description|
65
+
|:--:|:--:|:-----:|:----------|
66
+
|**`preview`**|`{Boolean}`|false|Will display a preview of the files that are to be omitted in the console (Will not actually omit)|
67
+
|**`cacheOnWatch`**|`{Boolean}`|false|Whether it should cache the JS filenames that should be omitted, on watch|
68
+
|**`verbose`**|`{Boolean}`|false|Whether it should display which files will be omitted to the console|
69
+
70
+
## Additional Notes
71
+
Although, this plugin supports caching the omissable files on watch, ideally you shouldn't be using this plugin during Development. Rather, it is highly recommended that you only include this plugin when you are building for production.
"description": "This Webpack plugin will omit the JS files, for CSS only dependencies, that become obsolete once extract-text-plugin extracts all inlined CSS into its own .css file",
* @description : This plugin will omit the JS entry files, for CSS only dependencies, that become obsolete once extract-text-plugin extracts all inlined CSS into its own .css file.
4
+
*/
5
+
6
+
constchalk=require('chalk');
7
+
8
+
/**
9
+
* @param {Object} options - Configurable options
10
+
* @constructor
11
+
*/
12
+
functionOmitJSforCSSPlugin(options){
13
+
constdefaults={
14
+
preview : false,// OPTIONAL - {Boolean} - A preview of the files that are to be omitted (Will not actually omit)
15
+
cacheOnWatch : false,// OPTIONAL - {Boolean} - Whether it should cache the JS filenames that should be omitted on watch
16
+
verbose : false// OPTIONAL - {Boolean} - Whether it should display which files will be omitted
console.log(chalk.bold(chalk.red('PREVIEW'))+chalk.grey(' File to be omitted for ')+chalk.bold(chalk.green(omitted.chunkName))+' : '+chalk.bold(chalk.green(omitted.filename)));
35
+
}
36
+
else{
37
+
this.options.verbose&&console.log(chalk.grey('File Omitted for ')+chalk.bold(chalk.green(omitted.chunkName))+chalk.grey(' : ')+chalk.bold(chalk.green(omitted.filename)));
0 commit comments