-
Notifications
You must be signed in to change notification settings - Fork 23
Emit the created content as well #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
//cc @Idorobots |
Hi! Thanks! Waiting for confirmation from @Idorobots. |
@@ -20,6 +20,8 @@ module.exports = function(source, map) { | |||
// creator.create(..., source) tells the module to operate on the | |||
// source variable. Check API for more details. | |||
creator.create(this.resourcePath, source).then(content => { | |||
// Emit the created content as well | |||
this.emitFile(this.resourcePath + '.d.ts', content.contents || ['']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use content.outputFilePath
in order to support outDir
query parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content.outputFilePath
has the .d.ts
at the end, right?
I'm still getting an error on the first, clean build in my setup. As mentioned in #7, in my case it seems to not matter as the build continues but I'm not sure that it'll be the case for others. |
@Idorobots does it work if you create a CSS file in a project after you started webpack watch? |
@olegstepura, initially it fails to build the bundle, but it compiles properly after I edit a .ts file that imports this .css file again. Webpack doesn't crash, so I suppose it's usable, but I wouldn't say it works either. |
The way I went around it was to create a global dummy declare module '*.css' {
const result: any;
export = result;
} In my editor, I see TypeScript complaining if I use a class that doesn't exist in the CSS file so it means it uses the local |
@Idorobots updated. Although this works very well (if you add the |
Can we use a pitching loader to do this process instead? |
@mohsen1 Is there anything you are going to add to this PR? |
Well, this + that module declaration works for us but if you misspell a class name it will not fail due to forgiving I'm experimenting with pitching loaders. It's exactly what we're looking for. We want the metadata and don't care about input and output. We only want to produce some side effect early on. The only problem I have is that pitching loaders are sync and DSTCreator is async. So when I do something like this, sometimes some modules fail because the async process took more than one CPU tick... Do you know if DST Creator can be sync? var DtsCreator = require('typed-css-modules');
var loaderUtils = require('loader-utils');
var objectAssign = require('object-assign');
module.exports.pitch = function(fullpath) {
this.cacheable && this.cacheable();
var parts = fullpath.split('!');
var name = parts[parts.length - 1];
var creator = new DtsCreator();
creator.create(name).then((content) => {
content.writeFile();
});
return;
}; |
@Quramy how hard is it to make sync methods for DTS Creator? |
oh I guess I can use |
@mohsen1 Could you be so kind to update README accordingly? So that other users would be informed. Also I'm thinking of adding (that) module declaration to loader sources, so that it would be in a release to just include it in a project codebase. |
@olegstepura Will do if that's the final solution but if I can make the pitching loader work, it would be unnecessary to all of those hacks and it will work as anyone expect. |
ok still struggling with making the pitch loader to
I'm pretty sure |
@mohsen1 Ok, let's wait then ;) |
@mohsen1 Can this already be merged? Or do you plan to add more commits? |
No this will not fix the original issue |
Is it harmless to merge this? |
Not necessarily. It will work better for the second run. |
Sorry, I'm confused... If it's better to merge this and it will not hurt anyone, I will merge this. |
@olegstepura I just tried this with our CI system. Not emitting the TSDs broke our build. Could you please merge this change and release it? Thanks |
Merged and released v0.0.6. |
Fix crashes in path for !moduleMode
Very similar to #7 but emits created contnet as well. I tried it on my setup and it works.