@enhanced-dom/webpack 0.0.3 → 0.0.4

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
@@ -22,5 +22,5 @@ const loaders = __importStar(require("./loaders"));
22
22
  const plugins = __importStar(require("./plugins"));
23
23
  module.exports = {
24
24
  loaders,
25
- plugins,
25
+ plugins
26
26
  };
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
- const loader_utils_1 = require("loader-utils");
3
2
  const loader = function () { };
3
+ const styleLoader = require('style-loader');
4
+ const uniqueId = require('lodash').uniqueId;
4
5
  loader.pitch = function pitch(remainingRequest) {
5
6
  if (this.cacheable) {
6
7
  this.cacheable();
7
8
  }
8
- return `
9
- var content = require(${loader_utils_1.stringifyRequest(this, `!!${remainingRequest}`)});
10
- module.exports = content.locals || {};
11
- module.exports._source = content.toString();
9
+ const result = styleLoader.pitch.call(this, remainingRequest);
10
+ const index = result.indexOf('var update = API(content, options)');
11
+ if (index <= -1)
12
+ return result;
13
+ const insertIndex = index - 1;
14
+ const stylesheetName = uniqueId('stylesheet-');
15
+ const insertAttr = `
16
+ options.attributes = options.attributes || {}
17
+ options.attributes.title = "${stylesheetName}";
12
18
  `;
19
+ return result.slice(0, insertIndex) + insertAttr + result.slice(insertIndex) + `export const _stylesheetName = "${stylesheetName}";`;
13
20
  };
14
21
  module.exports = loader;
@@ -23,15 +23,13 @@ export declare const nullConfigFactory: ({ rules }?: {
23
23
  export declare const fontExtensions: string[];
24
24
  export declare const imageExtensions: string[];
25
25
  export declare const assetExtensions: (extensions?: string[]) => RegExp;
26
- export declare const babelConfigFactory: ({ babel, cache }?: {
26
+ export declare const babelConfigFactory: ({ babel }: {
27
27
  babel?: any;
28
- cache?: boolean | Record<string, any>;
29
28
  }) => {
30
29
  loader: string;
31
30
  options: any;
32
31
  }[];
33
- export declare const markdownConfigFactory: ({ babel, cache, remark, }?: {
32
+ export declare const markdownConfigFactory: ({ babel, remark, }?: {
34
33
  babel?: any;
35
- cache?: boolean | Record<string, any>;
36
34
  remark?: any[];
37
35
  }) => any[];
package/loaders/index.js CHANGED
@@ -19,23 +19,28 @@ const styleConfigFactory = ({ raw = false, extract = false, sourceMap = false, t
19
19
  if (raw) {
20
20
  loaders.push({
21
21
  loader: ExposeCssSourceLoader,
22
+ options: {
23
+ attributes: {}
24
+ }
22
25
  });
23
26
  }
24
- const finalStyleLoader = extract
25
- ? {
27
+ else if (extract) {
28
+ loaders.push({
26
29
  loader: mini_css_extract_plugin_1.default.loader,
27
30
  options: {
28
31
  publicPath: './',
29
- },
30
- }
31
- : { loader: 'style-loader' };
32
- loaders.push(finalStyleLoader);
32
+ }
33
+ });
34
+ }
35
+ else {
36
+ loaders.push({ loader: 'style-loader' });
37
+ }
33
38
  if (typedStyles) {
34
39
  loaders.push({
35
40
  loader: 'dts-css-modules-loader',
36
41
  options: {
37
42
  namedExport: true,
38
- banner: raw ? 'export const _source: string;' : undefined,
43
+ banner: raw ? 'export const _stylesheetName: string;' : undefined,
39
44
  },
40
45
  });
41
46
  }
@@ -112,18 +117,15 @@ exports.fontExtensions = ['ttf', 'eot', 'woff', 'woff2'];
112
117
  exports.imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'ico'];
113
118
  const assetExtensions = (extensions = [...exports.imageExtensions, ...exports.fontExtensions]) => new RegExp(`\\.(${extensions.join('|')})(\\?.*$|$)?$`);
114
119
  exports.assetExtensions = assetExtensions;
115
- const babelConfigFactory = ({ babel = undefined, cache = false } = {}) => {
120
+ const babelConfigFactory = ({ babel = undefined }) => {
116
121
  const loaders = [{ loader: 'babel-loader', options: babel }];
117
- if (cache) {
118
- loaders.unshift({ loader: 'cache-loader', options: { cacheDirectory: '.babelcache', ...cache } });
119
- }
120
122
  return loaders;
121
123
  };
122
124
  exports.babelConfigFactory = babelConfigFactory;
123
- const markdownConfigFactory = ({ babel, cache, remark = [], } = {}) => {
125
+ const markdownConfigFactory = ({ babel, remark = [], } = {}) => {
124
126
  const loaders = [];
125
127
  if (babel) {
126
- loaders.push(...exports.babelConfigFactory({ babel, cache }));
128
+ loaders.push(...exports.babelConfigFactory({ babel }));
127
129
  loaders.push({
128
130
  loader: '@mdx-js/loader',
129
131
  options: {
@@ -132,9 +134,6 @@ const markdownConfigFactory = ({ babel, cache, remark = [], } = {}) => {
132
134
  });
133
135
  }
134
136
  else {
135
- if (cache) {
136
- loaders.push({ loader: 'cache-loader', options: { cacheDirectory: '.markdowncache', ...cache } });
137
- }
138
137
  loaders.push({
139
138
  loader: 'html-loader',
140
139
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enhanced-dom/webpack",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Helpers for webpack configuration",
5
5
  "keywords": [],
6
6
  "repository": "https://github.com/enhanced-dom/webpack.git",
@@ -18,7 +18,6 @@
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",
@@ -41,6 +40,7 @@
41
40
  "postcss-advanced-variables": "^3.0.1",
42
41
  "postcss-scss": "^4.0.0",
43
42
  "module-from-string": "^3.0.0",
43
+ "raw-loader": "^4.0.2",
44
44
  "remark-code-import": "^0.3.0",
45
45
  "remark-embed-images": "^2.0.0",
46
46
  "remark-images": "^2.0.0",
@@ -71,7 +71,8 @@
71
71
  "overrides": {
72
72
  "postcss": "^8.2.15",
73
73
  "postcss-scss": "^4.0.0",
74
- "autoprefixer": "^10.3.5"
74
+ "autoprefixer": "^10.3.5",
75
+ "webpack": "^5.28.0"
75
76
  },
76
77
  "engines": {
77
78
  "node": ">=14.17.0",
@@ -13,8 +13,7 @@ export declare const htmlConfigFactory: ({ html, embed, outputPath }?: {
13
13
  html?: Partial<HtmlWebpackPlugin.Options>;
14
14
  outputPath?: string;
15
15
  }) => WebpackPluginInstance[];
16
- export declare const terserConfigFactory: ({ enableSourcemaps, cachePath, terserOptions, }?: {
16
+ export declare const terserConfigFactory: ({ enableSourcemaps, terserOptions, }?: {
17
17
  enableSourcemaps?: boolean;
18
- cachePath?: string;
19
18
  terserOptions?: MinifyOptions;
20
19
  }) => TerserPlugin[];
package/plugins/index.js CHANGED
@@ -68,10 +68,10 @@ const htmlConfigFactory = ({ html = {}, embed, outputPath = './dist' } = {}) =>
68
68
  return plugins;
69
69
  };
70
70
  exports.htmlConfigFactory = htmlConfigFactory;
71
- const terserConfigFactory = ({ enableSourcemaps = true, cachePath = './.tersercache', terserOptions = {}, } = {}) => [
71
+ const terserConfigFactory = ({ enableSourcemaps = true, terserOptions = {}, } = {}) => [
72
72
  new terser_webpack_plugin_1.default({
73
73
  parallel: true,
74
- cache: cachePath,
74
+ cache: true,
75
75
  sourceMap: enableSourcemaps,
76
76
  terserOptions: {
77
77
  ie8: false,