Skip to content

Commit 5977d1a

Browse files
authored
Merge pull request olegstepura#5 from Naycon/master
Support for DtsCreator parameters via query parameters
2 parents 05438b1 + f85fa88 commit 5977d1a

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
npm-debug.log
2+
node_modules

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# typed-css-modules-loader
22

33
Simplest webpack loader for https://github.com/Quramy/typed-css-modules
4-
Has no configuration atm.
54

6-
I suggest using it as preloader. It will generate `.css.d.ts` files near the `.css`
7-
Please take a look at [this discussion](https://github.com/Quramy/typed-css-modules/issues/2) to make a decision.
5+
I suggest using it as preloader. Unless you change the options (see below), it
6+
will generate `.css.d.ts` files near the `.css`. Please take a look at
7+
[this discussion](https://github.com/Quramy/typed-css-modules/issues/2) to make a decision.
8+
9+
You can affect how `typed-css-modules` behaves by using query parameters. The loader
10+
will pass any query parameters you specify to the constructor of the `DtsCreator`
11+
class. For more info on available options, please take a look here:
12+
[DtsCreator constructor](https://github.com/Quramy/typed-css-modules#new-dtscreatoroption).
13+
814

915
```js
1016

@@ -17,6 +23,8 @@ const settings = {
1723
test: /\.css$/,
1824
exclude: /node_modules/,
1925
loader: 'typed-css-modules'
26+
// or in case you want to use parameters:
27+
// loader: 'typed-css-modules?outDir=/tmp'
2028
}
2129
],
2230
}

index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
var DtsCreator = require('typed-css-modules');
2-
3-
var creator = new DtsCreator();
2+
var loaderUtils = require('loader-utils');
3+
var objectAssign = require('object-assign');
44

55
module.exports = function(source, map) {
66
this.cacheable && this.cacheable();
77
var callback = this.async();
8-
8+
9+
// Pass on query parameters as an options object to the DtsCreator. This lets
10+
// you change the default options of the DtsCreator and e.g. use a different
11+
// output folder.
12+
var queryOptions = loaderUtils.parseQuery(this.query);
13+
var options;
14+
if (queryOptions) {
15+
options = objectAssign({}, queryOptions);
16+
}
17+
18+
var creator = new DtsCreator(options);
19+
920
// creator.create(..., source) tells the module to operate on the
1021
// source variable. Check API for more details.
1122
creator.create(this.resourcePath, source).then(content => {

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
"license": "MIT",
2323
"bugs": {
2424
"url": "https://github.com/olegstepura/typed-css-modules-loader/issues"
25+
},
26+
"dependencies": {
27+
"loader-utils": "^0.2.15",
28+
"object-assign": "^4.1.0"
2529
}
2630
}

0 commit comments

Comments
 (0)