Socket
Socket
Sign inDemoInstall

assets-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-webpack-plugin - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

spec/fixtures/styles.js

28

index.js

@@ -50,9 +50,28 @@ var fs = require('fs');

var assets = {};
// filterDevChunks
// Return true if a chunk is not a source map
// @param {String} chunk value e.g. index-bundle.js.map
// @return {Boolean}
function filterDevChunks(value) {
return !(
/source-?map/.test(compiler.options.devtool) &&
/\.map$/.test(value)
);
}
// webpackStatsJson.assetsByChunkName contains a hash with the bundle names and the produced files
// e.g. { one: 'one-bundle.js', two: 'two-bundle.js' }
// in some cases (when using a plugin or source maps) it might contain an array of produced files
// e.g. { main: [ 'index-bundle.js', 'index-bundle.js.map' ] }
for (var chunk in webpackStatsJson.assetsByChunkName) {
var chunkValue = webpackStatsJson.assetsByChunkName[chunk];
// Webpack outputs an array for each chunk when using sourcemaps
// Webpack outputs an array for each chunk when using sourcemaps and some plugins
if (chunkValue instanceof Array) {
// Is the main bundle always the first element?
chunkValue = chunkValue[0];
// When using plugins like 'extract-text', for extracting CSS from JS, webpack
// will push the new bundle to the array, so the last item will be the correct
// chunk
// e.g. [ 'styles-bundle.js', 'styles-bundle.css' ]
chunkValue = chunkValue.filter(filterDevChunks).pop();
}

@@ -63,2 +82,3 @@

}
assets[chunk] = chunkValue;

@@ -70,2 +90,2 @@ }

module.exports = Plugin;
module.exports = Plugin;

5

package.json
{
"name": "assets-webpack-plugin",
"version": "0.1.0",
"version": "0.2.0",
"description": "Emits a json file with assets paths",

@@ -27,2 +27,4 @@ "main": "index.js",

"devDependencies": {
"css-loader": "^0.9.1",
"extract-text-webpack-plugin": "^0.3.8",
"jasmine-node": "^1.14.5",

@@ -32,4 +34,5 @@ "jshint": "^2.5.2",

"rimraf": "^2.2.8",
"style-loader": "^0.8.3",
"webpack": "^1.3.3-beta1"
}
}

@@ -12,2 +12,8 @@ assets-webpack-plugin

## Install
```
npm install assets-webpack-plugin --save
```
## Configuration

@@ -19,3 +25,3 @@

var path = require("path");
var SaveHashes = require('./hash');
var SaveAssetsJson = require('assets-webpack-plugin');

@@ -30,3 +36,3 @@ module.exports = {

....
plugins: [new SaveHashes()]
plugins: [new SaveAssetsJson()]
};

@@ -84,1 +90,7 @@ ```

## Test
```
npm test
```
var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var rm_rf = require('rimraf');

@@ -156,2 +157,32 @@ var mkdirp = require('mkdirp');

});
it('works with ExtractTextPlugin for stylesheets', function(done) {
var webpackConfig = {
entry: {
one: path.join(__dirname, 'fixtures/one.js'),
two: path.join(__dirname, 'fixtures/two.js'),
styles: path.join(__dirname, 'fixtures/styles.js')
},
output: {
path: OUTPUT_DIR,
filename: '[name]-bundle.js'
},
module: {
loaders: [
{test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader')}
]
},
plugins: [
new ExtractTextPlugin('[name]-bundle.css', {allChunks: true}),
new Plugin({
path: 'dist'
})
]
};
var expected = ['{"one":"one-bundle.js","two":"two-bundle.js","styles":"styles-bundle.css"}'];
testPlugin(webpackConfig, expected, null, done);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc