Skip to content

Commit

Permalink
Major upgrade for eslint and support webpack 4
Browse files Browse the repository at this point in the history
  • Loading branch information
almothafar committed Mar 15, 2018
1 parent 4a00c52 commit 0ed80b1
Show file tree
Hide file tree
Showing 5 changed files with 1,202 additions and 39 deletions.
11 changes: 8 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "standard",
"extends": "eslint:recommended",
"rules": {
"indent": ["error", 4]
}
"indent": "off",
"indent-legacy": ["error", 4]
},
"env": {
"node": true,
"es6": true
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CircleCI](https://circleci.com/gh/szrenwei/inline-manifest-webpack-plugin/tree/master.svg?style=shield)](https://circleci.com/gh/szrenwei/inline-manifest-webpack-plugin/tree/master) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![npm](https://img.shields.io/npm/dt/inline-manifest-webpack-plugin.svg)](https://www.npmjs.com/package/inline-manifest-webpack-plugin) [![npm](https://img.shields.io/npm/v/inline-manifest-webpack-plugin.svg)](https://www.npmjs.com/package/inline-manifest-webpack-plugin) [![npm](https://img.shields.io/npm/l/inline-manifest-webpack-plugin.svg)](https://www.npmjs.com/package/inline-manifest-webpack-plugin)
[![CircleCI](https://circleci.com/gh/almothafar/webpack-inline-manifest-plugin/tree/master.svg?style=shield)](https://circleci.com/gh/almothafar/webpack-inline-manifest-plugin/tree/master) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) [![npm](https://img.shields.io/npm/dt/webpack-inline-manifest-plugin.svg)](https://www.npmjs.com/package/webpack-inline-manifest-plugin) [![npm](https://img.shields.io/npm/v/webpack-inline-manifest-plugin.svg)](https://www.npmjs.com/package/webpack-inline-manifest-plugin) [![npm](https://img.shields.io/npm/l/webpack-inline-manifest-plugin.svg)](https://www.npmjs.com/package/webpack-inline-manifest-plugin)

Inline Manifest Webpack Plugin
===================
Expand All @@ -10,7 +10,7 @@ Installation
------------
Install the plugin with npm:
```shell
$ npm i inline-manifest-webpack-plugin -D
$ npm i webpack-inline-manifest-plugin -D
```

Basic Usage
Expand Down
45 changes: 22 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
var sourceMappingURL = require('source-map-url')
const sourceMappingURL = require('source-map-url');

function InlineManifestPlugin (options) {
function InlineManifestPlugin(options) {
this.options = extend({
name: 'webpackManifest'
}, options || {})
}

InlineManifestPlugin.prototype.apply = function (compiler) {
var me = this
const me = this;

compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-before-html-generation', function (htmlPluginData, callback) {
var name = me.options.name
const name = me.options.name;
// HtmlWebpackPlugin use the 'manifest' name as HTML5's app cache manifest
// so we can't use the same name
if (name === 'manifest') {
throw new Error('[InlineManifestWebpackPlugin]: name can\'t be "manifest".')
throw new Error('[WebpackInlineManifestPlugin]: name can\'t be "manifest".')
}

var webpackManifest = []
var assets = htmlPluginData.assets
var manifestPath = (compilation.chunks.filter(function (chunk) {
const webpackManifest = [];
const assets = htmlPluginData.assets;
const manifestPath = (compilation.chunks.filter(function (chunk) {
return chunk.name === 'manifest'
})[0] || {files: []}).files[0]
})[0] || {files: []}).files[0];

if (manifestPath) {
webpackManifest.push('<script>')
webpackManifest.push(sourceMappingURL.removeFrom(compilation.assets[manifestPath].source()))
webpackManifest.push('</script>')
webpackManifest.push('<script>');
webpackManifest.push(sourceMappingURL.removeFrom(compilation.assets[manifestPath].source()));
webpackManifest.push('</script>');

var manifestIndex = assets.js.indexOf(assets.publicPath + manifestPath)
const manifestIndex = assets.js.indexOf(assets.publicPath + manifestPath);
if (manifestIndex >= 0) {
assets.js.splice(manifestIndex, 1)
assets.js.splice(manifestIndex, 1);
delete assets.chunks.manifest
}
}

assets[name] = webpackManifest.join('')
assets[name] = webpackManifest.join('');
if (callback) {
callback(null, htmlPluginData)
}
})
})
}
};

function extend (base) {
var i = 1
var len = arguments.length
function extend(base) {
const len = arguments.length;

for (; i < len; i++) {
var obj = arguments[i]
for (var key in obj) {
for (let i = 1; i < len; i++) {
const obj = arguments[i];
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
base[key] = obj[key]
}
Expand All @@ -60,4 +59,4 @@ function extend (base) {
return base
}

module.exports = InlineManifestPlugin
module.exports = InlineManifestPlugin;
Loading

0 comments on commit 0ed80b1

Please sign in to comment.