@enhanced-dom/webpack 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,14 +1,24 @@
1
1
  "use strict";
2
- const loader_utils_1 = require("loader-utils");
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const style_loader_1 = __importDefault(require("style-loader"));
6
+ const lodash_1 = require("lodash");
3
7
  const loader = function () { };
4
8
  loader.pitch = function pitch(remainingRequest) {
5
9
  if (this.cacheable) {
6
10
  this.cacheable();
7
11
  }
8
- return `
9
- var content = require(${loader_utils_1.stringifyRequest(this, `!!${remainingRequest}`)});
10
- module.exports = content.locals || {};
11
- module.exports._source = content.toString();
12
+ const result = style_loader_1.default.pitch.call(this, remainingRequest);
13
+ const index = result.indexOf('var update = API(content, options)');
14
+ if (index <= -1)
15
+ return result;
16
+ const insertIndex = index - 1;
17
+ const stylesheetName = (0, lodash_1.uniqueId)('stylesheet-');
18
+ const insertAttr = `
19
+ options.attributes = options.attributes || {}
20
+ options.attributes.title = "${stylesheetName}";
12
21
  `;
22
+ return result.slice(0, insertIndex) + insertAttr + result.slice(insertIndex) + `export const _stylesheetName = "${stylesheetName}";`;
13
23
  };
14
24
  module.exports = loader;
@@ -20,36 +20,16 @@ export declare const nullConfigFactory: ({ rules }?: {
20
20
  use: string;
21
21
  enforce: string;
22
22
  }[];
23
- export declare const assetsConfigFactory: {
24
- ({ embed, extraConfig, pathPrefix }?: {
25
- embed?: boolean;
26
- extraConfig?: {};
27
- pathPrefix?: string;
28
- }): {
29
- loader: string;
30
- options: {
31
- esModule: boolean;
32
- };
33
- }[] | {
34
- loader: string;
35
- options: {
36
- esModule: boolean;
37
- name: string;
38
- };
39
- }[];
40
- fontExtensions: string[];
41
- imageExtensions: string[];
42
- extensions(extensions?: string[]): RegExp;
43
- };
44
- export declare const babelConfigFactory: ({ babel, cache }?: {
23
+ export declare const fontExtensions: string[];
24
+ export declare const imageExtensions: string[];
25
+ export declare const assetExtensions: (extensions?: string[]) => RegExp;
26
+ export declare const babelConfigFactory: ({ babel }: {
45
27
  babel?: any;
46
- cache?: boolean | Record<string, any>;
47
28
  }) => {
48
29
  loader: string;
49
30
  options: any;
50
31
  }[];
51
- export declare const markdownConfigFactory: ({ babel, cache, remark, }?: {
32
+ export declare const markdownConfigFactory: ({ babel, remark }?: {
52
33
  babel?: any;
53
- cache?: boolean | Record<string, any>;
54
34
  remark?: any[];
55
35
  }) => any[];
package/loaders/index.js CHANGED
@@ -3,16 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.markdownConfigFactory = exports.babelConfigFactory = exports.assetsConfigFactory = exports.nullConfigFactory = exports.styleConfigFactory = void 0;
6
+ exports.markdownConfigFactory = exports.babelConfigFactory = exports.assetExtensions = exports.imageExtensions = exports.fontExtensions = exports.nullConfigFactory = exports.styleConfigFactory = void 0;
7
7
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
8
- const path_1 = __importDefault(require("path"));
9
8
  const postcss_import_webpack_resolver_1 = __importDefault(require("postcss-import-webpack-resolver"));
10
9
  const ExposeCssSourceLoader = require.resolve('./ExposeCssSourceLoader');
11
- // @ts-ignore
12
10
  const remark_code_import_1 = __importDefault(require("remark-code-import"));
13
- // @ts-ignore
14
11
  const remark_unwrap_images_1 = __importDefault(require("remark-unwrap-images"));
15
- // @ts-ignore
16
12
  const remark_embed_images_1 = __importDefault(require("remark-embed-images"));
17
13
  const styleConfigFactory = ({ raw = false, extract = false, sourceMap = false, typedStyles = false, modules = undefined, parser = undefined, aliases = {}, } = {}) => {
18
14
  var _a;
@@ -20,23 +16,28 @@ const styleConfigFactory = ({ raw = false, extract = false, sourceMap = false, t
20
16
  if (raw) {
21
17
  loaders.push({
22
18
  loader: ExposeCssSourceLoader,
19
+ options: {
20
+ attributes: {},
21
+ },
23
22
  });
24
23
  }
25
- const finalStyleLoader = extract
26
- ? {
24
+ else if (extract) {
25
+ loaders.push({
27
26
  loader: mini_css_extract_plugin_1.default.loader,
28
27
  options: {
29
28
  publicPath: './',
30
29
  },
31
- }
32
- : { loader: 'style-loader' };
33
- loaders.push(finalStyleLoader);
30
+ });
31
+ }
32
+ else {
33
+ loaders.push({ loader: 'style-loader' });
34
+ }
34
35
  if (typedStyles) {
35
36
  loaders.push({
36
37
  loader: 'dts-css-modules-loader',
37
38
  options: {
38
39
  namedExport: true,
39
- banner: raw ? 'export const _source: string;' : undefined,
40
+ banner: raw ? 'export const _stylesheetName: string;' : undefined,
40
41
  },
41
42
  });
42
43
  }
@@ -81,7 +82,7 @@ const styleConfigFactory = ({ raw = false, extract = false, sourceMap = false, t
81
82
  [
82
83
  'postcss-import',
83
84
  {
84
- resolve: postcss_import_webpack_resolver_1.default({
85
+ resolve: (0, postcss_import_webpack_resolver_1.default)({
85
86
  alias: aliases,
86
87
  }),
87
88
  modules: ['./node_modules', 'node_modules'],
@@ -109,27 +110,19 @@ const nullConfigFactory = ({ rules = [] } = {}) => {
109
110
  }));
110
111
  };
111
112
  exports.nullConfigFactory = nullConfigFactory;
112
- const assetsConfigFactory = ({ embed = false, extraConfig = {}, pathPrefix = 'static' } = {}) => {
113
- return embed
114
- ? [{ loader: 'url-loader', options: { esModule: false, ...extraConfig } }]
115
- : [{ loader: 'file-loader', options: { esModule: false, name: path_1.default.join(pathPrefix, '[name].[ext]'), ...extraConfig } }];
116
- };
117
- exports.assetsConfigFactory = assetsConfigFactory;
118
- exports.assetsConfigFactory.fontExtensions = ['ttf', 'eot', 'woff', 'woff2'];
119
- exports.assetsConfigFactory.imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'svg'];
120
- exports.assetsConfigFactory.extensions = (extensions = [...exports.assetsConfigFactory.imageExtensions, ...exports.assetsConfigFactory.fontExtensions]) => new RegExp(`\\.(${extensions.join('|')})(\\?.*$|$)?$`);
121
- const babelConfigFactory = ({ babel = undefined, cache = false } = {}) => {
113
+ exports.fontExtensions = ['ttf', 'eot', 'woff', 'woff2'];
114
+ exports.imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'ico'];
115
+ const assetExtensions = (extensions = [...exports.imageExtensions, ...exports.fontExtensions]) => new RegExp(`\\.(${extensions.join('|')})(\\?.*$|$)?$`);
116
+ exports.assetExtensions = assetExtensions;
117
+ const babelConfigFactory = ({ babel = undefined }) => {
122
118
  const loaders = [{ loader: 'babel-loader', options: babel }];
123
- if (cache) {
124
- loaders.unshift({ loader: 'cache-loader', options: { cacheDirectory: '.babelcache', ...cache } });
125
- }
126
119
  return loaders;
127
120
  };
128
121
  exports.babelConfigFactory = babelConfigFactory;
129
- const markdownConfigFactory = ({ babel, cache, remark = [], } = {}) => {
122
+ const markdownConfigFactory = ({ babel, remark = [] } = {}) => {
130
123
  const loaders = [];
131
124
  if (babel) {
132
- loaders.push(...exports.babelConfigFactory({ babel, cache }));
125
+ loaders.push(...(0, exports.babelConfigFactory)({ babel }));
133
126
  loaders.push({
134
127
  loader: '@mdx-js/loader',
135
128
  options: {
@@ -138,9 +131,6 @@ const markdownConfigFactory = ({ babel, cache, remark = [], } = {}) => {
138
131
  });
139
132
  }
140
133
  else {
141
- if (cache) {
142
- loaders.push({ loader: 'cache-loader', options: { cacheDirectory: '.markdowncache', ...cache } });
143
- }
144
134
  loaders.push({
145
135
  loader: 'html-loader',
146
136
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enhanced-dom/webpack",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "Helpers for webpack configuration",
5
5
  "keywords": [],
6
6
  "repository": "https://github.com/enhanced-dom/webpack.git",
@@ -18,12 +18,12 @@
18
18
  "@mdx-js/loader": "^1.6.22",
19
19
  "autoprefixer": "^10.3.5",
20
20
  "babel-loader": "^8.2.2",
21
- "cache-loader": "^4.1.0",
22
21
  "copyfiles": "^2.4.1",
23
22
  "css-loader": "^6.2.0",
24
23
  "cssnano-preset-advanced": "^5.1.3",
25
24
  "dts-css-modules-loader": "^1.2.3",
26
- "file-loader": "^6.2.0",
25
+ "html-inline-css-webpack-plugin": "^1.11.1",
26
+ "html-inline-script-webpack-plugin": "^2.0.3",
27
27
  "html-loader": "^2.1.2",
28
28
  "html-webpack-inline-source-plugin": "^0.0.10",
29
29
  "html-webpack-plugin": "^5.3.1",
@@ -40,6 +40,7 @@
40
40
  "postcss-advanced-variables": "^3.0.1",
41
41
  "postcss-scss": "^4.0.0",
42
42
  "module-from-string": "^3.0.0",
43
+ "raw-loader": "^4.0.2",
43
44
  "remark-code-import": "^0.3.0",
44
45
  "remark-embed-images": "^2.0.0",
45
46
  "remark-images": "^2.0.0",
@@ -49,12 +50,10 @@
49
50
  "source-map-loader": "^3.0.0",
50
51
  "style-loader": "^3.2.1",
51
52
  "terser-webpack-plugin": "^5.1.2",
52
- "url-loader": "^4.1.1",
53
- "webpack": "^5.53.0",
54
- "webpack-bundle-analyzer": "^4.4.2",
55
- "webpack-cli": "^4.8.0",
56
- "webpack-dev-server": "^4.2.1",
57
- "semver": "^7.3.5",
53
+ "webpack": "^5.70.0",
54
+ "webpack-bundle-analyzer": "^4.5.0",
55
+ "webpack-cli": "^4.9.2",
56
+ "webpack-dev-server": "^4.7.4",
58
57
  "serve": "^12.0.0"
59
58
  },
60
59
  "devDependencies": {
@@ -63,16 +62,16 @@
63
62
  "@types/loader-utils": "^2.0.2",
64
63
  "@types/mini-css-extract-plugin": "^1.4.3",
65
64
  "@types/optimize-css-assets-webpack-plugin": "^5.0.3",
66
- "@types/terser-webpack-plugin": "^5.0.3",
65
+ "@types/terser-webpack-plugin": "^5.2.0",
67
66
  "@types/webpack": "^5.28.0",
68
67
  "@types/webpack-bundle-analyzer": "^2.9.2",
69
68
  "typescript": "^4.2.2"
70
-
71
69
  },
72
70
  "overrides": {
73
71
  "postcss": "^8.2.15",
74
72
  "postcss-scss": "^4.0.0",
75
- "autoprefixer": "^10.3.5"
73
+ "autoprefixer": "^10.3.5",
74
+ "terser": "^5.12.1"
76
75
  },
77
76
  "engines": {
78
77
  "node": ">=14.17.0",
@@ -3,39 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
6
- // @ts-ignore
7
6
  const html_webpack_inline_source_plugin_1 = __importDefault(require("html-webpack-inline-source-plugin"));
8
- html_webpack_inline_source_plugin_1.default.prototype.processTags = function (compilation, regexStr, pluginData) {
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ html_webpack_inline_source_plugin_1.default.prototype.processTags = function (compilation, pluginData) {
9
10
  const self = this;
10
- const scripts = [];
11
- const styles = [];
12
- const regex = new RegExp(regexStr);
13
- pluginData.assetTags.scripts.forEach(function (tag) {
14
- scripts.push(self.processTag(compilation, regex, tag));
11
+ const headTags = [];
12
+ const bodyTags = [];
13
+ pluginData.headTags.forEach((tag) => {
14
+ headTags.push(self.processTag(compilation, self.assetsRegExp, tag));
15
15
  });
16
- pluginData.assetTags.styles.forEach(function (tag) {
17
- styles.push(self.processTag(compilation, regex, tag));
16
+ pluginData.bodyTags.forEach((tag) => {
17
+ bodyTags.push(self.processTag(compilation, self.assetsRegExp, tag));
18
18
  });
19
- return { ...pluginData, assetTags: { ...pluginData.assetTags, scripts, styles } };
19
+ return { ...pluginData, headTags, bodyTags };
20
20
  };
21
21
  html_webpack_inline_source_plugin_1.default.prototype.apply = function (compiler) {
22
22
  const self = this;
23
23
  self.assetsRegExp = undefined;
24
+ self.faviconPath = undefined;
24
25
  compiler.hooks.compilation.tap('html-webpack-inline-source-plugin', (compilation) => {
25
- html_webpack_plugin_1.default.getHooks(compilation).alterAssetTags.tapAsync('html-webpack-inline-source-plugin', (htmlPluginData, callback) => {
26
- if (!htmlPluginData.plugin.options.inlineSource) {
27
- return callback(null, htmlPluginData);
26
+ html_webpack_plugin_1.default.getHooks(compilation).afterTemplateExecution.tapAsync('html-webpack-inline-source-plugin', (htmlPluginData, callback) => {
27
+ self.assetsRegExp = new RegExp('.(js|css)$');
28
+ const result = self.processTags(compilation, htmlPluginData);
29
+ const favicon = htmlPluginData.plugin.options.favicon;
30
+ if (!favicon || !fs_1.default.existsSync(favicon)) {
31
+ return callback(null, result);
32
+ }
33
+ const faviconTag = result.headTags.find((tag) => tag.tagName === 'link' && tag.attributes.rel === 'icon');
34
+ if (faviconTag) {
35
+ self.faviconPath = faviconTag.attributes.href;
36
+ faviconTag.attributes.href = `data:image/x-icon;base64, ${fs_1.default.readFileSync(favicon, 'base64')}`;
28
37
  }
29
- const regexStr = htmlPluginData.plugin.options.inlineSource;
30
- self.assetsRegExp = new RegExp(regexStr);
31
- const result = self.processTags(compilation, regexStr, htmlPluginData);
32
38
  callback(null, result);
33
39
  });
34
40
  });
35
41
  compiler.hooks.emit.tap('html-webpack-inline-source-plugin', (compilation) => {
36
42
  if (self.assetsRegExp) {
37
43
  Object.keys(compilation.assets).forEach(function (file) {
38
- if (file.match(self.assetsRegExp)) {
44
+ var _a, _b;
45
+ if (file.match(self.assetsRegExp) || file === ((_b = (_a = self.faviconPath) === null || _a === void 0 ? void 0 : _a.split(path_1.default.sep)) === null || _b === void 0 ? void 0 : _b.pop())) {
39
46
  delete compilation.assets[file];
40
47
  }
41
48
  });
@@ -1,18 +1,20 @@
1
1
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
2
+ import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
3
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
2
4
  import TerserPlugin from 'terser-webpack-plugin';
3
5
  import { MinifyOptions } from 'terser';
4
6
  import HtmlWebpackPlugin from 'html-webpack-plugin';
7
+ import { WebpackPluginInstance } from 'webpack';
5
8
  export declare const cssConfigFactory: ({ filename, cssnanoOptions, }?: {
6
9
  filename?: string;
7
10
  cssnanoOptions?: any;
8
- }) => any[];
11
+ }) => (MiniCssExtractPlugin | CssMinimizerPlugin<CssMinimizerPlugin.CssNanoOptionsExtended>)[];
9
12
  export declare const bundleAnalyzerConfigFactory: (extraConfig?: BundleAnalyzerPlugin.Options) => BundleAnalyzerPlugin[];
10
13
  export declare const htmlConfigFactory: ({ html, embed }?: {
11
14
  embed?: boolean;
12
15
  html?: Partial<HtmlWebpackPlugin.Options>;
13
- }) => HtmlWebpackPlugin[];
14
- export declare const terserConfigFactory: ({ enableSourcemaps, cachePath, terserOptions, }?: {
16
+ }) => WebpackPluginInstance[];
17
+ export declare const terserConfigFactory: ({ enableSourcemaps, terserOptions }?: {
15
18
  enableSourcemaps?: boolean;
16
- cachePath?: string;
17
19
  terserOptions?: MinifyOptions;
18
- }) => TerserPlugin[];
20
+ }) => TerserPlugin<MinifyOptions>[];
package/plugins/index.js CHANGED
@@ -55,12 +55,11 @@ const htmlConfigFactory = ({ html = {}, embed } = {}) => {
55
55
  const favicon = html.favicon ? (path_1.default.isAbsolute(html.favicon) ? html.favicon : path_1.default.join(process.cwd(), html.favicon)) : undefined;
56
56
  const plugins = [
57
57
  new html_webpack_plugin_1.default({
58
- inject: true,
59
- inlineSource: embed ? '.(js|css)$' : undefined,
58
+ inject: 'body',
60
59
  lang: 'en-US',
61
60
  ...(templateExists ? { template } : { templateContent }),
62
61
  ...html,
63
- favicon: favicon && embed && fs_1.default.existsSync(favicon) ? `data:image/x-icon;base64, ${fs_1.default.readFileSync(favicon, 'base64')}` : favicon,
62
+ favicon,
64
63
  }),
65
64
  ];
66
65
  if (embed) {
@@ -69,13 +68,12 @@ const htmlConfigFactory = ({ html = {}, embed } = {}) => {
69
68
  return plugins;
70
69
  };
71
70
  exports.htmlConfigFactory = htmlConfigFactory;
72
- const terserConfigFactory = ({ enableSourcemaps = true, cachePath = './.tersercache', terserOptions = {}, } = {}) => [
71
+ const terserConfigFactory = ({ enableSourcemaps = true, terserOptions = {} } = {}) => [
73
72
  new terser_webpack_plugin_1.default({
74
73
  parallel: true,
75
- cache: cachePath,
76
- sourceMap: enableSourcemaps,
77
74
  terserOptions: {
78
75
  ie8: false,
76
+ sourceMap: enableSourcemaps,
79
77
  compress: {
80
78
  evaluate: false,
81
79
  },