This repository has been archived by the owner on Apr 5, 2021. It is now read-only.
v3.3.1
What's New in v3.3.1
This is a summary of the differences between v3.3.1 and v3.3.0.
Commits
Show commits
SHA | Author | Message |
---|---|---|
ba54b60 |
mmiller42 | Spaces are probably better |
30ce0d4 |
mmiller42 | Move config schema to separate file for readability |
f365c6b |
mmiller42 | 3.3.1 |
Changed files
.babelrc
Show changes
@@ -1,17 +1,17 @@
{
- "presets": [
- [
- "babel-preset-env",
- {
- "targets": {
- "node": "4.3.0"
- }
- }
- ]
- ],
- "plugins": [
- "babel-plugin-add-module-exports",
- "babel-plugin-transform-class-properties",
- "babel-plugin-transform-object-rest-spread"
- ]
+ "presets": [
+ [
+ "babel-preset-env",
+ {
+ "targets": {
+ "node": "4.3.0"
+ }
+ }
+ ]
+ ],
+ "plugins": [
+ "babel-plugin-add-module-exports",
+ "babel-plugin-transform-class-properties",
+ "babel-plugin-transform-object-rest-spread"
+ ]
}
.editorconfig
Show changes
@@ -1,8 +1,8 @@
root = true
-[src/**.js]
-indent_style = tab
-indent_size = tab
+[{src/**.{js,json},*.json,.babelrc,*.md}]
+indent_style = space
+indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
package-lock.json
Inline diff not displayed. View the whole file
package.json
Show changes
@@ -1,57 +1,57 @@
{
- "name": "html-webpack-externals-plugin",
- "version": "3.3.0",
- "description": "Webpack plugin that works alongside html-webpack-plugin to use pre-packaged vendor bundles.",
- "keywords": [
- "htmlwebpackplugin",
- "webpack",
- "html",
- "externals"
- ],
- "main": "lib/index.js",
- "scripts": {
- "prepack": "npm run build",
- "precommit": "lint-staged",
- "build": "rm -rf lib && babel src --out-dir lib --source-maps --copy-files",
- "watch": "npm run build -- --watch"
- },
- "lint-staged": {
- "*.js": [
- "prettier --write --use-tabs --no-semi --single-quote --trailing-comma es5 'src/**/*.js'",
- "git add"
- ]
- },
- "engines": {
- "node": ">=4.3.0 <5.0.0 || >=5.10"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/mmiller42/html-webpack-externals-plugin.git"
- },
- "author": "Matt Miller <[email protected]>",
- "license": "MIT",
- "bugs": {
- "url": "https://github.com/mmiller42/html-webpack-externals-plugin/issues"
- },
- "homepage": "https://github.com/mmiller42/html-webpack-externals-plugin#readme",
- "devDependencies": {
- "babel-cli": "^6.24.1",
- "babel-core": "^6.25.0",
- "babel-plugin-add-module-exports": "^0.2.1",
- "babel-plugin-transform-class-properties": "^6.24.1",
- "babel-plugin-transform-object-rest-spread": "^6.23.0",
- "babel-preset-env": "^1.6.0",
- "husky": "^0.14.3",
- "lint-staged": "^4.0.1",
- "prettier": "^1.5.3"
- },
- "peerDependencies": {
- "html-webpack-plugin": "^2.0.0",
- "webpack": "^2.0.0"
- },
- "dependencies": {
- "ajv": "^5.2.2",
- "copy-webpack-plugin": "^4.0.1",
- "html-webpack-include-assets-plugin": "0.0.7"
- }
+ "name": "html-webpack-externals-plugin",
+ "version": "3.3.1",
+ "description": "Webpack plugin that works alongside html-webpack-plugin to use pre-packaged vendor bundles.",
+ "keywords": [
+ "htmlwebpackplugin",
+ "webpack",
+ "html",
+ "externals"
+ ],
+ "main": "lib/index.js",
+ "scripts": {
+ "prepack": "npm run build",
+ "precommit": "lint-staged",
+ "build": "rm -rf lib && babel src --out-dir lib --source-maps --copy-files",
+ "watch": "npm run build -- --watch"
+ },
+ "lint-staged": {
+ "*.js": [
+ "prettier --write --no-semi --single-quote --trailing-comma es5 '{src/**/*.{js,json},*.json}'",
+ "git add"
+ ]
+ },
+ "engines": {
+ "node": ">=4.3.0 <5.0.0 || >=5.10"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/mmiller42/html-webpack-externals-plugin.git"
+ },
+ "author": "Matt Miller <[email protected]>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/mmiller42/html-webpack-externals-plugin/issues"
+ },
+ "homepage": "https://github.com/mmiller42/html-webpack-externals-plugin#readme",
+ "devDependencies": {
+ "babel-cli": "^6.24.1",
+ "babel-core": "^6.25.0",
+ "babel-plugin-add-module-exports": "^0.2.1",
+ "babel-plugin-transform-class-properties": "^6.24.1",
+ "babel-plugin-transform-object-rest-spread": "^6.23.0",
+ "babel-preset-env": "^1.6.0",
+ "husky": "^0.14.3",
+ "lint-staged": "^4.0.1",
+ "prettier": "^1.5.3"
+ },
+ "peerDependencies": {
+ "html-webpack-plugin": "^2.0.0",
+ "webpack": "^2.0.0"
+ },
+ "dependencies": {
+ "ajv": "^5.2.2",
+ "copy-webpack-plugin": "^4.0.1",
+ "html-webpack-include-assets-plugin": "0.0.7"
+ }
}
src/HtmlWebpackExternalsPlugin.js
Show changes
@@ -1,168 +1,120 @@
import CopyWebpackPlugin from 'copy-webpack-plugin'
import HtmlWebpackIncludeAssetsPlugin from 'html-webpack-include-assets-plugin'
import Ajv from 'ajv'
+import configSchema from './configSchema.json'
export default class HtmlWebpackExternalsPlugin {
- static validateArguments = (() => {
- const ajv = new Ajv({ useDefaults: true })
- const validateConfig = ajv.compile({
- type: 'object',
- properties: {
- externals: {
- type: 'array',
- items: {
- type: 'object',
- properties: {
- module: { type: 'string' },
- entry: {
- type: ['string', 'array', 'object'],
- items: {
- type: ['string', 'object'],
- properties: {
- path: { type: 'string' },
- type: { type: 'string', enum: ['js', 'css'] },
- },
- required: ['path', 'type'],
- },
- minItems: 1,
- properties: {
- path: { type: 'string' },
- type: { type: 'string', enum: ['js', 'css'] },
- },
- required: ['path', 'type'],
- },
- global: { type: ['string', 'null'], default: null },
- supplements: {
- type: 'array',
- items: { type: 'string' },
- default: [],
- },
- append: { type: 'boolean', default: false },
- },
- required: ['module', 'entry'],
- },
- minItems: 1,
- },
- hash: { type: 'boolean', default: false },
- outputPath: { type: 'string', default: 'vendor' },
- publicPath: { type: ['string', 'null'], default: null },
- files: {
- type: ['string', 'array', 'null'],
- items: { type: 'string' },
- minItems: 1,
- default: null,
- },
- },
- required: ['externals'],
- })
-
- return config => {
- if (!validateConfig(config)) {
- throw new TypeError(ajv.errorsText(validateConfig.errors))
- }
- }
- })()
-
- static URL_ENTRY = /^(http:|https:)?\/\//
-
- constructor(config) {
- HtmlWebpackExternalsPlugin.validateArguments(config)
-
- this.assetsToPrepend = []
- this.assetsToAppend = []
- this.assetsToCopy = []
- this.externals = {}
-
- const { externals, hash, outputPath, publicPath, files } = config
- this.hash = hash
- this.outputPath = outputPath
- this.publicPath = publicPath
- this.files = files
-
- externals.forEach(({ module, entry, global, supplements, append }) => {
- this.externals[module] = global
-
- const localEntries = []
-
- const entries = (Array.isArray(entry) ? entry : [entry]).map(entry => {
- if (typeof entry === 'string') {
- entry = { path: entry, type: null }
- }
- if (HtmlWebpackExternalsPlugin.URL_ENTRY.test(entry.path)) {
- return entry
- }
- const localEntry = \`${module}/${entry.path}\`
- localEntries.push(localEntry)
- return { ...entry, path: localEntry }
- })
-
- if (append) {
- this.assetsToAppend = [...this.assetsToAppend, ...entries]
- } else {
- this.assetsToPrepend = [...this.assetsToPrepend, ...entries]
- }
-
- this.assetsToCopy = [
- ...this.assetsToCopy,
- ...localEntries,
- ...supplements.map(asset => \`${module}/${asset}\`),
- ]
- })
- }
-
- apply(compiler) {
- if (!compiler.options.externals) {
- compiler.options.externals = this.externals
- } else if (Array.isArray(compiler.options.externals)) {
- compiler.options.externals.push(this.externals)
- } else if (typeof compiler.options.externals === 'object') {
- compiler.options.externals = {
- ...compiler.options.externals,
- ...this.externals,
- }
- }
-
- const publicPath =
- this.publicPath == null
- ? compiler.options.output.publicPath
- : this.publicPath
-
- const pluginsToApply = []
-
- pluginsToApply.push(
- new CopyWebpackPlugin(
- this.assetsToCopy.map(asset => ({
- from: \`node_modules/${asset}\`,
- to: \`${this.outputPath}/${asset}\`,
- }))
- )
- )
-
- const createAssetsPlugin = (assets, append) => {
- if (assets.length) {
- pluginsToApply.push(
- new HtmlWebpackIncludeAssetsPlugin({
- assets: assets.map(
- asset =>
- HtmlWebpackExternalsPlugin.URL_ENTRY.test(asset.path)
- ? asset
- : {
- ...asset,
- path: \`${publicPath}${this.outputPath}/${asset.path}\`,
- }
- ),
- append,
- hash: this.hash,
- files: this.files,
- publicPath: '',
- })
- )
- }
- }
-
- createAssetsPlugin(this.assetsToPrepend, false)
- createAssetsPlugin(this.assetsToAppend, true)
-
- pluginsToApply.forEach(plugin => plugin.apply(compiler))
- }
+ static validateArguments = (() => {
+ const ajv = new Ajv({ useDefaults: true })
+ const validateConfig = ajv.compile(configSchema)
+
+ return config => {
+ if (!validateConfig(config)) {
+ throw new TypeError(ajv.errorsText(validateConfig.errors))
+ }
+ }
+ })()
+
+ static URL_ENTRY = /^(http:|https:)?\/\//
+
+ constructor(config) {
+ HtmlWebpackExternalsPlugin.validateArguments(config)
+
+ this.assetsToPrepend = []
+ this.assetsToAppend = []
+ this.assetsToCopy = []
+ this.externals = {}
+
+ const { externals, hash, outputPath, publicPath, files } = config
+ this.hash = hash
+ this.outputPath = outputPath
+ this.publicPath = publicPath
+ this.files = files
+
+ externals.forEach(({ module, entry, global, supplements, append }) => {
+ this.externals[module] = global
+
+ const localEntries = []
+
+ const entries = (Array.isArray(entry) ? entry : [entry]).map(entry => {
+ if (typeof entry === 'string') {
+ entry = { path: entry, type: null }
+ }
+ if (HtmlWebpackExternalsPlugin.URL_ENTRY.test(entry.path)) {
+ return entry
+ }
+ const localEntry = \`${module}/${entry.path}\`
+ localEntries.push(localEntry)
+ return { ...entry, path: localEntry }
+ })
+
+ if (append) {
+ this.assetsToAppend = [...this.assetsToAppend, ...entries]
+ } else {
+ this.assetsToPrepend = [...this.assetsToPrepend, ...entries]
+ }
+
+ this.assetsToCopy = [
+ ...this.assetsToCopy,
+ ...localEntries,
+ ...supplements.map(asset => \`${module}/${asset}\`),
+ ]
+ })
+ }
+
+ apply(compiler) {
+ if (!compiler.options.externals) {
+ compiler.options.externals = this.externals
+ } else if (Array.isArray(compiler.options.externals)) {
+ compiler.options.externals.push(this.externals)
+ } else if (typeof compiler.options.externals === 'object') {
+ compiler.options.externals = {
+ ...compiler.options.externals,
+ ...this.externals,
+ }
+ }
+
+ const publicPath =
+ this.publicPath == null
+ ? compiler.options.output.publicPath
+ : this.publicPath
+
+ const pluginsToApply = []
+
+ pluginsToApply.push(
+ new CopyWebpackPlugin(
+ this.assetsToCopy.map(asset => ({
+ from: \`node_modules/${asset}\`,
+ to: \`${this.outputPath}/${asset}\`,
+ }))
+ )
+ )
+
+ const createAssetsPlugin = (assets, append) => {
+ if (assets.length) {
+ pluginsToApply.push(
+ new HtmlWebpackIncludeAssetsPlugin({
+ assets: assets.map(
+ asset =>
+ HtmlWebpackExternalsPlugin.URL_ENTRY.test(asset.path)
+ ? asset
+ : {
+ ...asset,
+ path: \`${publicPath}${this.outputPath}/${asset.path}\`,
+ }
+ ),
+ append,
+ hash: this.hash,
+ files: this.files,
+ publicPath: '',
+ })
+ )
+ }
+ }
+
+ createAssetsPlugin(this.assetsToPrepend, false)
+ createAssetsPlugin(this.assetsToAppend, true)
+
+ pluginsToApply.forEach(plugin => plugin.apply(compiler))
+ }
}
➕ src/configSchema.json
Show changes
@@ -0,0 +1,81 @@
+{
+ "type": "object",
+ "properties": {
+ "externals": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "module": {
+ "type": "string"
+ },
+ "entry": {
+ "type": ["string", "array", "object"],
+ "items": {
+ "type": ["string", "object"],
+ "properties": {
+ "path": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string",
+ "enum": ["js", "css"]
+ }
+ },
+ "required": ["path", "type"]
+ },
+ "minItems": 1,
+ "properties": {
+ "path": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string",
+ "enum": ["js", "css"]
+ }
+ },
+ "required": ["path", "type"]
+ },
+ "global": {
+ "type": ["string", "null"],
+ "default": null
+ },
+ "supplements": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": []
+ },
+ "append": {
+ "type": "boolean",
+ "default": false
+ }
+ },
+ "required": ["module", "entry"]
+ },
+ "minItems": 1
+ },
+ "hash": {
+ "type": "boolean",
+ "default": false
+ },
+ "outputPath": {
+ "type": "string",
+ "default": "vendor"
+ },
+ "publicPath": {
+ "type": ["string", "null"],
+ "default": null
+ },
+ "files": {
+ "type": ["string", "array", "null"],
+ "items": {
+ "type": "string"
+ },
+ "minItems": 1,
+ "default": null
+ }
+ },
+ "required": ["externals"]
+}