-
Notifications
You must be signed in to change notification settings - Fork 71
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
How to force recompile? #19
Comments
The problem isn't with preval, but with the babel cache. You could disable that and it should work (though I don't think that it would recompile in watch mode unless you change the importing file anyway). Perhaps @hzoo has some ideas for us 😀 |
Another way to get around this problem would be to use the import syntax or the |
Thanks for your suggestion! I updated my demo with |
Thanks for giving that a try. Surprised that didn't work! I don't have any time to dedicate to working on this particular issue right now, so anyone's welcome to help with this! Thanks! |
Hey I've just taken a look. It's definitely that Something like this should work: {
"verbose": false,
"ignore": ["node_modules"],
"env": {
"NODE_ENV": "development",
"BABEL_DISABLE_CACHE": 1
},
"execMap": {
"js": "babel-node"
},
"ext": ".js,.md",
"watch": "./src/"
} Then your |
Just ran into this with my docs stuff 😅 I have to manually go in and save the file to recompile. I'm using the import syntax as well with no luck. Going to try and see if I can figure anything out. Some of this stuff is over my head, but I'll report any findings. |
Thanks @souporserious! I experience this with Next.js and it's pretty annoying, I wind up just adding a |
Babel's caching is definitely lacking. There's no core functionality for it, so everyone implements it outside core, which means there aren't any core primitives to express when caches should be invalidated. I'm still hoping I can get something like that into core for 7.x, but I can't promise it'll happen. |
How can we help you @loganfsmyth? |
Good question. Basically trying to figure out how I can actually get paid to do something interesting at the moment, because working on Babel full-time for free for a few months has kind of eaten through my motivation :( |
Ah! You're still looking for a job? Ping me on twitter DM or something and we'll see if we can help you find something! 😄 |
Another workaround is clearing out the babel cache folder (default at "scripts": {
"start": "yarn clear:babel-cache && next",
"build": "yarn clear:babel-cache next build && next export",
"clear:babel-cache": "rimraf -rf ./node_modules/.cache/babel-loader/*"
} |
Is it bad to set up a watch task and have that run every time a file is changed @kenvunz? Been sort of a rough workflow having to start and stop my dev server to see any changes would love to have it work on file change. |
Bad? No. Performant? No also. Is it noticable? Depends, but probably not. |
Has anyone gotten this to work with webpack-dev-server? I tried disabling babel-cache by setting an environment variable with no luck :/ I still have to start and stop the server to get any changes. |
@souporserious |
Hmm interesting 🤔 I don't have that set at all. Is it possible babel cache doesn't have anything to do with not getting the changes? Could it be something else? Here's my config:
|
You know I don't think I actually thought through my comment last night properly, sorry. With your setup, it's Webpack itself that is doing the in-memory caching. If you change a referenced file in preval, Webpack has no way of knowing that the JS file needs to be reprocessed. The Babel build process would actually have to return a list of referenced files so Webpack could be told what to watch. I'm not actually 100% sure Webpack exposes an API for that, though I know it does expose an |
Ahh I see 😕 thanks for the explanation! A little over my head, but I'll see if I can get anywhere. This stuff is so powerful, I can deal with the nuances for now 😸 |
I don't think there's anything we can do in this package to make this work. Would someone like to document this issue in the README (in the FAQ)? Then we can close this. |
Workaround: module.rules: [
{
// add this before the babel-loader
test: path.resolve(__dirname, "file.js"),
use: {
loader: path.resolve(__dirname, "add-dependency-loader.js"),
options: {
file: path.resolve(__dirname, "file.md")
}
}
}
] // add-dependency-loader.js
module.exports = function(source, map) {
this.addDependency(this.query.file);
this.callback(null, source, map);
} |
I am not sure this is the right place to follow up the babel cache problem. As you know I am working on Maybe we should add a note in the babel-plugin-macros repository? |
Yes, we should probably add a "caveats" section for things that are currently problems that we're still working on. Would you like to do that @evenchange4? |
Sure, I will send a PR later. |
I had only one file called I made a simple node script called const fs = require('fs');
const path = require('path');
let filesPath = path.join(__dirname, 'src', 'config', 'files.js');
setInterval(() => {
const file = fs.readFileSync(filesPath, 'utf8');
fs.writeFileSync(filesPath, file + ' ');
setTimeout(() => {
fs.writeFileSync(filesPath, file);
}, 100);
}, 1000); It works perfectly. |
@kitze that's a fantastic hack 💯 |
Whoops, didn't mean to close! That hack is not considered an "acceptable solution" 😉 |
I just published a lib for this purpose, it works by adding annotation to your js file:
when a specified dependency change, the file containing annotation is automatically recompiled, babel-watch-extra is coupled to nodemon here is the link: usage: It has also others advantages against official
|
@TakioN that's great but I still have no idea how to use your lib in combination with babel-plugin-preval? |
@kitze file.js
when a file is added, modified or deleted in directory1 or it's subdirectories, file.js will be recompiled by the watcher I use it with NodeJS, I don't know how to use it with webpack because it's not a babel plugin but a replacer for officiel babel watcher and so can't be loaded by babel-loader. |
I just noticed that this issue doesn't link to where this would really be solved. If this gets implemented, then we could solve this issue for real: babel/babel#8497 |
For me neither of those worked. Instead |
my opinion is that not every preval file needs to be recompiled every time, so we need another magic preval comment that will signal the preval plugin to recompile the file again every time. |
It's really helpful for me. Thanks |
I'm trying to display the commit hash of my application in the UI, and running into this whenever making a new commit or changing branches locally (it continues to show the old commit hash until I clear the cache). So far all the comments are about watching some other file, but does anyone have ideas about dealing with an external command? // @preval
const pkg = require('../../../package.json');
const { execSync } = require('child_process');
const shortRepoName = url => new URL(url).pathname.substring(1);
const trimHash = hash => hash.substring(0, 7);
const version = pkg => {
try {
const head = String(execSync('git rev-parse HEAD'));
const tag = String(execSync(`git rev-parse v${pkg.version}`));
if (head !== tag) return `${pkg.version}-${trimHash(head)}`;
} catch (e) {
// Continue
}
// Fall back to version in package.json
return pkg.version;
};
module.exports = {
name: pkg.name,
url: pkg.repository.url,
repository: shortRepoName(pkg.repository.url),
version: version(pkg),
}; My best idea is to watch for changes in the .git directory, but that's an entire folder. |
I figured out I could do this to avoid cache on a single file: const rules = [
{
// First is my "real" babel-loader rule
test: /\.(js|jsx|mjs)$/,
include: [source_path],
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true, // Cache is enabled
},
},
],
},
{
// Below I add babel-loader again, except I disable cache for just this file
test: resolve(__dirname, '../../app/soapbox/utils/code.js'),
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: false, // Cache is disabled
},
},
],
},
] The only problem is, it doesn't refresh automatically when the git repo changes. That could be fixed by adding a custom loader as suggested here: #19 (comment) EDIT: Watching |
If I understand the problem correctly this Babel/PR-11741 solves the issue by allowing to specify files as dependencies, causing them to rebuild... |
babel-plugin-preval
version: 1.4.1node
version: 8.1.3npm
(oryarn
) version: npm 5.2.0Relevant code or config
What you did: I ran the code above, to export contents of
file.md
.What happened: when I modify
file.md
the result ofpreval
didn't change when I tried to compile it again. Maybe I'm missing something?Reproduction repository: demo
Problem description:
preval
probably doesn't see the reason to recompile because its tagged template literal didn't change.Suggested solution: I don't know. 😅
The text was updated successfully, but these errors were encountered: