optimize-css-assets-webpack-plugin
Advanced tools
Comparing version
{ | ||
"name": "optimize-css-assets-webpack-plugin", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "A Webpack plugin to optimize \\ minimize CSS assets.", | ||
@@ -33,14 +33,14 @@ "keywords": [ | ||
"dependencies": { | ||
"cssnano": "^4.1.0", | ||
"cssnano": "^4.1.10", | ||
"last-call-webpack-plugin": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^22.1.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"css-loader": "^0.28.9", | ||
"babel-preset-env": "^1.7.0", | ||
"css-loader": "^3.0.0", | ||
"extract-text-webpack-plugin": "next", | ||
"jest": "^22.1.4", | ||
"jest": "^24.8.0", | ||
"style-loader": "^0.20.1", | ||
@@ -47,0 +47,0 @@ "webpack": "^4.9.1" |
@@ -25,7 +25,7 @@ # Optimize CSS Assets Webpack Plugin | ||
The plugin can receive the following options (all of them are optional): | ||
* assetNameRegExp: A regular expression that indicates the names of the assets that should be optimized \ minimized. The regular expression provided is run against the filenames of the files exported by the ExtractTextPlugin instances in your configuration, not the filenames of your source CSS files. Defaults to `/\.css$/g` | ||
* cssProcessor: The CSS processor used to optimize \ minimize the CSS, defaults to [cssnano](http://github.com/ben-eb/cssnano). This should be a function that follows cssnano.process interface (receives a CSS and options parameters and returns a Promise). | ||
* cssProcessorOptions: The options passed to the cssProcessor, defaults to `{}` | ||
* cssProcessorPluginOptions: The plugin options passed to the cssProcessor, defaults to `{}` | ||
* canPrint: A boolean indicating if the plugin can print messages to the console, defaults to `true` | ||
* `assetNameRegExp`: A regular expression that indicates the names of the assets that should be optimized \ minimized. The regular expression provided is run against the filenames of the files exported by the `ExtractTextPlugin` instances in your configuration, not the filenames of your source CSS files. Defaults to `/\.css$/g` | ||
* `cssProcessor`: The CSS processor used to optimize \ minimize the CSS, defaults to [`cssnano`](http://github.com/ben-eb/cssnano). This should be a function that follows `cssnano.process` interface (receives a CSS and options parameters and returns a Promise). | ||
* `cssProcessorOptions`: The options passed to the `cssProcessor`, defaults to `{}` | ||
* `cssProcessorPluginOptions`: The plugin options passed to the `cssProcessor`, defaults to `{}` | ||
* `canPrint`: A boolean indicating if the plugin can print messages to the console, defaults to `true` | ||
@@ -32,0 +32,0 @@ ## Example: |
@@ -0,1 +1,3 @@ | ||
const url = require('url'); | ||
const LastCallWebpackPlugin = require('last-call-webpack-plugin'); | ||
@@ -9,3 +11,3 @@ | ||
phase: LastCallWebpackPlugin.PHASES.OPTIMIZE_CHUNK_ASSETS, | ||
regExp: (options && options.assetNameRegExp) || /\.css$/g, | ||
regExp: (options && options.assetNameRegExp) || /\.css(\?.*)?$/i, | ||
processor: (assetName, asset, assets) => | ||
@@ -19,3 +21,3 @@ this.processCss(assetName, asset, assets), | ||
this.options.assetNameRegExp = !options || !options.assetNameRegExp ? | ||
/\.css$/g : | ||
/\.css(\?.*)?$/i : | ||
options.assetNameRegExp; | ||
@@ -38,2 +40,8 @@ this.options.cssProcessor = !options || !options.cssProcessor ? | ||
processCss(assetName, asset, assets) { | ||
const parse = url.parse(assetName); | ||
const assetInfo = { | ||
path: parse.pathname, | ||
query: parse.query ? `?${parse.query}` : '', | ||
}; | ||
const css = asset.sourceAndMap ? asset.sourceAndMap() : { source: asset.source() }; | ||
@@ -49,3 +57,3 @@ const processOptions = Object.assign( | ||
if (!map) { | ||
const mapJson = assets.getAsset(assetName + '.map'); | ||
const mapJson = assets.getAsset(`${assetInfo.path}.map`); | ||
if (mapJson) { | ||
@@ -72,3 +80,3 @@ map = JSON.parse(mapJson); | ||
if (processOptions.map && r.map && r.map.toString) { | ||
assets.setAsset(assetName + '.map', r.map.toString()); | ||
assets.setAsset(`${assetInfo.path}.map${assetInfo.query}`, r.map.toString()); | ||
} | ||
@@ -75,0 +83,0 @@ return r.css; |
@@ -13,4 +13,3 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin'; | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: true } | ||
loader: 'css-loader' | ||
} | ||
@@ -17,0 +16,0 @@ }) |
@@ -1,6 +0,6 @@ | ||
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | ||
import OptimizeCssAssetsPlugin from '../../../src/'; | ||
import ExtractTextPlugin from "extract-text-webpack-plugin"; | ||
import OptimizeCssAssetsPlugin from "../../../src/"; | ||
module.exports = { | ||
entry: './index', | ||
entry: "./index", | ||
module: { | ||
@@ -11,14 +11,11 @@ rules: [ | ||
use: ExtractTextPlugin.extract({ | ||
fallback: { loader: 'style-loader' }, | ||
fallback: { loader: "style-loader" }, | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: true } | ||
loader: "css-loader" | ||
} | ||
}) | ||
}, | ||
], | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('file.css') | ||
], | ||
plugins: [new ExtractTextPlugin("file.css")] | ||
}; |
@@ -1,9 +0,9 @@ | ||
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | ||
import OptimizeCssAssetsPlugin from '../../../src/'; | ||
import ExtractTextPlugin from "extract-text-webpack-plugin"; | ||
import OptimizeCssAssetsPlugin from "../../../src/"; | ||
const notToProcess = new ExtractTextPlugin('as_is.css'); | ||
const toProcess = new ExtractTextPlugin('optimize.css'); | ||
const notToProcess = new ExtractTextPlugin("as_is.css"); | ||
const toProcess = new ExtractTextPlugin("optimize.css"); | ||
module.exports = { | ||
entry: './index', | ||
entry: "./index", | ||
module: { | ||
@@ -14,6 +14,5 @@ rules: [ | ||
use: notToProcess.extract({ | ||
fallback: { loader: 'style-loader' }, | ||
fallback: { loader: "style-loader" }, | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: false } | ||
loader: "css-loader" | ||
} | ||
@@ -25,10 +24,9 @@ }) | ||
use: toProcess.extract({ | ||
fallback: { loader: 'style-loader' }, | ||
fallback: { loader: "style-loader" }, | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: false } | ||
loader: "css-loader" | ||
} | ||
}) | ||
} | ||
], | ||
] | ||
}, | ||
@@ -41,3 +39,3 @@ plugins: [ | ||
}) | ||
], | ||
] | ||
}; |
@@ -1,6 +0,6 @@ | ||
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | ||
import OptimizeCssAssetsPlugin from '../../../src/'; | ||
import ExtractTextPlugin from "extract-text-webpack-plugin"; | ||
import OptimizeCssAssetsPlugin from "../../../src/"; | ||
module.exports = { | ||
entry: './index', | ||
entry: "./index", | ||
module: { | ||
@@ -11,15 +11,11 @@ rules: [ | ||
use: ExtractTextPlugin.extract({ | ||
fallback: { loader: 'style-loader' }, | ||
fallback: { loader: "style-loader" }, | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: true } | ||
loader: "css-loader" | ||
} | ||
}) | ||
}, | ||
], | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new ExtractTextPlugin('file.css'), | ||
new OptimizeCssAssetsPlugin() | ||
], | ||
plugins: [new ExtractTextPlugin("file.css"), new OptimizeCssAssetsPlugin()] | ||
}; |
@@ -1,10 +0,10 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import ExtractTextPlugin from "extract-text-webpack-plugin"; | ||
export function readFileOrEmpty(path) { | ||
try { | ||
return fs.readFileSync(path, 'utf-8'); | ||
return fs.readFileSync(path, "utf-8"); | ||
} catch (e) { | ||
return ''; | ||
return ""; | ||
} | ||
@@ -14,3 +14,3 @@ } | ||
export const defaultConfig = { | ||
entry: './index', | ||
entry: "./index", | ||
module: { | ||
@@ -21,10 +21,9 @@ rules: [ | ||
use: ExtractTextPlugin.extract({ | ||
fallback: { loader: 'style-loader' }, | ||
fallback: { loader: "style-loader" }, | ||
use: { | ||
loader: 'css-loader', | ||
options: { minimize: true } | ||
loader: "css-loader" | ||
} | ||
}) | ||
}, | ||
], | ||
} | ||
] | ||
}, | ||
@@ -34,10 +33,10 @@ plugins: [], | ||
output: { | ||
filename: 'destination.js', | ||
path: path.resolve(__dirname, '../', 'js', 'default-exports') | ||
filename: "destination.js", | ||
path: path.resolve(__dirname, "../", "js", "default-exports") | ||
} | ||
}; | ||
export function checkForWebpackErrors({err, stats, done}) { | ||
export function checkForWebpackErrors({ err, stats, done }) { | ||
if (err) return done(err); | ||
if (stats.hasErrors()) return done(new Error(stats.toString())); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
17391
-0.74%364
-9.68%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated