@microsoft/webpack5-load-themed-styles-loader 0.1.0
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/LICENSE +24 -0
- package/README.md +76 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@microsoft/webpack5-load-themed-styles-loader
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @microsoft/webpack5-load-themed-styles-loader
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
`npm install @microsoft/webpack5-load-themed-styles-loader --save-dev`
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This simple Webpack loader that wraps the loading of CSS in script equivalent
|
|
10
|
+
to `require("@microsoft/load-themed-styles").loadStyles( /* css text */ )`.
|
|
11
|
+
It is designed to be a replacement for style-loader.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
|
|
16
|
+
|
|
17
|
+
This loader is designed to be used in conjunction with css-loader.
|
|
18
|
+
|
|
19
|
+
``` javascript
|
|
20
|
+
var css = require("@microsoft/webpack5-load-themed-styles-loader!css!./file.css");
|
|
21
|
+
// => returns css code from file.css, uses load-themed-styles to load the CSS on the page.
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Example config
|
|
25
|
+
|
|
26
|
+
``` javascript
|
|
27
|
+
use: [
|
|
28
|
+
{
|
|
29
|
+
loader: "@microsoft/webpack5-load-themed-styles-loader", // creates style nodes from JS strings
|
|
30
|
+
options: {
|
|
31
|
+
async: false
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
loader: "css-loader", // translates CSS into CommonJS
|
|
36
|
+
options: {
|
|
37
|
+
modules: true,
|
|
38
|
+
importLoaders: 2,
|
|
39
|
+
localIdentName: '[name]_[local]_[hash:base64:5]',
|
|
40
|
+
minimize: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
loader: 'postcss-loader',
|
|
45
|
+
options: {
|
|
46
|
+
plugins: function () {
|
|
47
|
+
return [
|
|
48
|
+
require('autoprefixer')
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
loader: "sass-loader",
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
### `async` (boolean, defaults to `false`)
|
|
63
|
+
|
|
64
|
+
By default, `@microsoft/load-themed-styles` loads styles synchronously. This can have adverse performance effects
|
|
65
|
+
if many styles are loaded in quick succession. If the `async` option is set to `true`, the `loadStyles` function
|
|
66
|
+
is called with the second parameter set to `true`, directing the function to debounce style loading causing fewer
|
|
67
|
+
changes to the DOM.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Links
|
|
71
|
+
|
|
72
|
+
- [CHANGELOG.md](
|
|
73
|
+
https://github.com/microsoft/rushstack/blob/main/webpack/webpack5-loader-load-themed-styles/CHANGELOG.md) - Find
|
|
74
|
+
out what's new in the latest version
|
|
75
|
+
|
|
76
|
+
`@microsoft/webpack5-load-themed-styles-loader` is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This simple loader wraps the loading of CSS in script equivalent to
|
|
3
|
+
* require("\@microsoft/load-themed-styles").loadStyles('... css text ...').
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { PitchLoaderDefinitionFunction } from 'webpack';
|
|
7
|
+
/**
|
|
8
|
+
* Options for the loader.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface ILoadThemedStylesLoaderOptions {
|
|
13
|
+
/**
|
|
14
|
+
* If this parameter is set to "true," the "loadAsync" parameter is set to true in the call to loadStyles.
|
|
15
|
+
* Defaults to false.
|
|
16
|
+
*/
|
|
17
|
+
async?: boolean;
|
|
18
|
+
loadThemedStylesPath?: string;
|
|
19
|
+
esModule?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* This simple loader wraps the loading of CSS in script equivalent to
|
|
23
|
+
* require("load-themed-styles").loadStyles('... css text ...').
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare const pitch: PitchLoaderDefinitionFunction<ILoadThemedStylesLoaderOptions>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAI5E;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AAEH,eAAO,MAAM,KAAK,EAAE,6BAA6B,CAAC,8BAA8B,CAqC/E,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.pitch = void 0;
|
|
6
|
+
const defaultThemedStylesPath = require.resolve('@microsoft/load-themed-styles');
|
|
7
|
+
/**
|
|
8
|
+
* This simple loader wraps the loading of CSS in script equivalent to
|
|
9
|
+
* require("load-themed-styles").loadStyles('... css text ...').
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
const pitch = function (remainingRequest) {
|
|
14
|
+
const loaderContext = this;
|
|
15
|
+
const options = loaderContext.getOptions() || {};
|
|
16
|
+
if (options.namedExport) {
|
|
17
|
+
throw new Error('The "namedExport" option has been removed.');
|
|
18
|
+
}
|
|
19
|
+
const { async = false, loadThemedStylesPath = defaultThemedStylesPath, esModule = false } = options;
|
|
20
|
+
const stringifiedRequest = JSON.stringify(loaderContext.utils.contextify(loaderContext.context, '!!' + remainingRequest));
|
|
21
|
+
const importCode = esModule
|
|
22
|
+
? [
|
|
23
|
+
`import content from ${stringifiedRequest};`,
|
|
24
|
+
`import { loadStyles } from ${JSON.stringify(loadThemedStylesPath)};`
|
|
25
|
+
]
|
|
26
|
+
: [
|
|
27
|
+
`var content = require(${stringifiedRequest});`,
|
|
28
|
+
`var loader = require(${JSON.stringify(loadThemedStylesPath)});`
|
|
29
|
+
];
|
|
30
|
+
return [
|
|
31
|
+
...importCode,
|
|
32
|
+
'',
|
|
33
|
+
'if(typeof content === "string") content = [[module.id, content]];',
|
|
34
|
+
'',
|
|
35
|
+
'// add the styles to the DOM',
|
|
36
|
+
`for (var i = 0; i < content.length; i++) ${esModule ? 'loadStyles' : 'loader.loadStyles'}(content[i][1], ${async === true});`,
|
|
37
|
+
'',
|
|
38
|
+
'if(content.locals) module.exports = content.locals;'
|
|
39
|
+
].join('\n');
|
|
40
|
+
};
|
|
41
|
+
exports.pitch = pitch;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAU3D,MAAM,uBAAuB,GAAW,OAAO,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAiBzF;;;;;GAKG;AAEI,MAAM,KAAK,GAAkE,UAElF,gBAAwB;IAExB,MAAM,aAAa,GAAkD,IAAI,CAAC;IAC1E,MAAM,OAAO,GAAmC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;IACjF,IAAK,OAAmC,CAAC,WAAW,EAAE;QACpD,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,oBAAoB,GAAG,uBAAuB,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACpG,MAAM,kBAAkB,GAAW,IAAI,CAAC,SAAS,CAC/C,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,GAAG,gBAAgB,CAAC,CAC/E,CAAC;IAEF,MAAM,UAAU,GAAkD,QAAQ;QACxE,CAAC,CAAC;YACE,uBAAuB,kBAAkB,GAAG;YAC5C,8BAA8B,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG;SACtE;QACH,CAAC,CAAC;YACE,yBAAyB,kBAAkB,IAAI;YAC/C,wBAAwB,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI;SACjE,CAAC;IAEN,OAAO;QACL,GAAG,UAAU;QACb,EAAE;QACF,mEAAmE;QACnE,EAAE;QACF,8BAA8B;QAC9B,4CACE,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,mBAC5B,mBAAmB,KAAK,KAAK,IAAI,IAAI;QACrC,EAAE;QACF,qDAAqD;KACtD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC;AArCW,QAAA,KAAK,SAqChB","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * This simple loader wraps the loading of CSS in script equivalent to\n * require(\"\\@microsoft/load-themed-styles\").loadStyles('... css text ...').\n * @packageDocumentation\n */\n\nimport type { LoaderContext, PitchLoaderDefinitionFunction } from 'webpack';\n\nconst defaultThemedStylesPath: string = require.resolve('@microsoft/load-themed-styles');\n\n/**\n * Options for the loader.\n *\n * @public\n */\nexport interface ILoadThemedStylesLoaderOptions {\n /**\n * If this parameter is set to \"true,\" the \"loadAsync\" parameter is set to true in the call to loadStyles.\n * Defaults to false.\n */\n async?: boolean;\n loadThemedStylesPath?: string;\n esModule?: boolean;\n}\n\n/**\n * This simple loader wraps the loading of CSS in script equivalent to\n * require(\"load-themed-styles\").loadStyles('... css text ...').\n *\n * @public\n */\n\nexport const pitch: PitchLoaderDefinitionFunction<ILoadThemedStylesLoaderOptions> = function (\n this: LoaderContext<ILoadThemedStylesLoaderOptions>,\n remainingRequest: string\n): string {\n const loaderContext: LoaderContext<ILoadThemedStylesLoaderOptions> = this;\n const options: ILoadThemedStylesLoaderOptions = loaderContext.getOptions() || {};\n if ((options as Record<string, unknown>).namedExport) {\n throw new Error('The \"namedExport\" option has been removed.');\n }\n\n const { async = false, loadThemedStylesPath = defaultThemedStylesPath, esModule = false } = options;\n const stringifiedRequest: string = JSON.stringify(\n loaderContext.utils.contextify(loaderContext.context, '!!' + remainingRequest)\n );\n\n const importCode: [contentImport: string, loaderImport: string] = esModule\n ? [\n `import content from ${stringifiedRequest};`,\n `import { loadStyles } from ${JSON.stringify(loadThemedStylesPath)};`\n ]\n : [\n `var content = require(${stringifiedRequest});`,\n `var loader = require(${JSON.stringify(loadThemedStylesPath)});`\n ];\n\n return [\n ...importCode,\n '',\n 'if(typeof content === \"string\") content = [[module.id, content]];',\n '',\n '// add the styles to the DOM',\n `for (var i = 0; i < content.length; i++) ${\n esModule ? 'loadStyles' : 'loader.loadStyles'\n }(content[i][1], ${async === true});`,\n '',\n 'if(content.locals) module.exports = content.locals;'\n ].join('\\n');\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.33.7"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@microsoft/webpack5-load-themed-styles-loader",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "This simple loader wraps the loading of CSS in script equivalent to `require('load-themed-styles').loadStyles( /* css text */ )`. It is designed to be a replacement for style-loader.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/microsoft/rushstack.git",
|
|
11
|
+
"directory": "webpack/webpack5-loader-load-themed-styles"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@microsoft/load-themed-styles": "^2.0.19"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@microsoft/load-themed-styles": "2.0.19",
|
|
18
|
+
"@rushstack/eslint-config": "3.1.1",
|
|
19
|
+
"@rushstack/heft-node-rig": "1.11.11",
|
|
20
|
+
"@rushstack/heft": "0.49.0",
|
|
21
|
+
"@types/heft-jest": "1.0.1",
|
|
22
|
+
"@types/node": "12.20.24",
|
|
23
|
+
"webpack": "~5.68.0",
|
|
24
|
+
"memfs": "3.4.3",
|
|
25
|
+
"css-loader": "~6.6.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "heft build --clean",
|
|
29
|
+
"_phase:build": "heft build --clean",
|
|
30
|
+
"_phase:test": "heft test --no-build"
|
|
31
|
+
}
|
|
32
|
+
}
|