Comments (7)
Why you need to watch php
files by webpack? We have such options for serve
(i.e. dev server to reload a page), but I don't see any reasons to just watch them by webpack itself
from webpack.
Why you need to watch
php
files by webpack? We have such options forserve
(i.e. dev server to reload a page), but I don't see any reasons to just watch them by webpack itself
I put the link if you want to get more details: symfony/webpack-encore#1246
But to explain here, when I use Symfony for example, and I use Bootstrap with "postcss-purgecss", it removes all unused classnames from the build, which means if I put for example "mt-5" classname on my php files (or twig), as it will not detect changes to "watch" and build, it will not include new classnames, so i need to update any js or css file to be able to build and get all used classnames. Let me know if it is not clear
from webpack.
I see your problem, that tools parse php files and extract classes (loader/plugin)?
from webpack.
I see your problem, that tools parse php files and extract classes (loader/plugin)?
Exactly, it works also with PostCSS. Ex my postcss.config.js
file content:
module.exports = {
plugins: [
require("autoprefixer"),
require("@fullhuman/postcss-purgecss")({
content: [
// PHP files from "src" and "vendor" directories that contain HTML/Twig templates
// In "vendor" directory, bundles like "knplabs pagination" are using bootstrap classes
"./src/**/*.php",
"./vendor/**/*.php",
"./vendor/**/*.html",
"./vendor/**/*.twig",
"./templates/**/*.twig",
"./assets/**/*.js",
"./assets/**/*.css",
],
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
}),
],
};
The "watch" works as well with js,css but not with php files, default configuration from webpack I guess. Is there any possibility to add our custom files to watch?
from webpack.
We have an API for such purposes and other tools use it (not only webpack, other bundlers too) - https://github.com/webpack-contrib/postcss-loader/blob/master/src/index.js#L191
@fullhuman/postcss-purgecss
should use postcss message API, i.e. run this code:
result.messages.push(
{
type: "dependency",
file: "/absolute/path/to/file.php",
plugin: "@fullhuman/postcss-purgecss",
}
)
Webpack knows nothing about PHP files, also just watching PHP files and rerun compilation will very ineffective, using such API (example above) webpack rebuild only modules which depend on /absolute/path/to/file.php
(i.e. in module where you imported CSS file where class was generated), so you will have fast rebuild.
from webpack.
Anyway, there is more old issue about it #13537, so let's close in favor #13537
from webpack.
For the people who will come across this issue, my problem has not been solved at all
Edit: I found a solution, for me, it was the best one: https://www.npmjs.com/package/webpack-watch-files-plugin
- npm install --save-dev webpack-watch-files-plugin
- in webpack.config.js add
const WatchFilesPlugin = require('webpack-watch-files-plugin').default;
module.exports = {
// ... other Webpack configuration
plugins: [
new WatchFilesPlugin({
files: ['src/**/*.php', 'templates/**/*'],
options: {
aggregateTimeout: 300, // Optional: Delay rebuild for 300ms
ignoreInitial: true // Optional: Avoid initial rebuild
}
})
]
};
For the people using webpack encore with Symfony, it is exactly the same, with some adjustements:
Encore
// Other configs....
.configureDevServerOptions((options) => {
options.liveReload = true;
options.static = {
watch: false,
};
options.watchFiles = {
paths: ["src/**/*.php", "templates/**/*"],
};
})
.addPlugin(new WatchFilesPlugin({
files: ['src/**/*.php', 'templates/**/*'],
options: {
aggregateTimeout: 300, // Optional: Delay rebuild for 300ms
ignoreInitial: true // Optional: Avoid initial rebuild
}
}));
from webpack.
Related Issues (20)
- Webpack 5 doesnt generate the chunks of imports HOT 1
- Error: Cannot find module 'webpack-cli/package.json' HOT 2
- Unable to bust cache of module federation remotes....
- Re-exported Ant Design components don't have same style with the original components
- failed to import ffmpeg-core.js HOT 3
- DllPlugin: When processing multiple chunks, does the `path` option must have a string template?
- Webpack BannerPlugin with `raw` option should put `use strict` on the very first line HOT 10
- After webpack 5 migration not able to use local packages in a mono repo
- 95% emitting emit phase takes much longer in Node >=16
- Plugin apply not working for multi compiler HOT 2
- packages/tailwindcss/src/compile.ts HOT 1
- Current error handling mainly involves calling the `onInvalidCandidate` callback function to handle invalid candidates, and printing corresponding error messages to the console.
- [5.91.0] "Fixed fs types" breaks `outputFileSystem` compatibility with `memfs` HOT 8
- Using `[name]` within `output.library`, the correct value isn't utilized in the source map namespace HOT 3
- Not found node_modules/@angular/common/bundles/common-http.umd.js
- webpack5.90.0 Modifying files in the node_modules directory (local component library) cannot trigger hot updates HOT 1
- Delete this.
- how to make webpack recompile on dev mode with cache on?
- Webpack build error for second time HOT 1
- `exportsPresence` does not work for unused imports HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack.