I'm currently experimenting with a monorepo architecture.
What I would like to do is in my web package where I run webpack dev server I'd like it to watch certain node_modules (symlinked local packages) for changes and trigger a "rebuild".
This way I'd be able to build dependencies separately and my browser would react to those changes.
My webpack config is the following:
var loaders = require('./../../../build/loaders-default'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var path = require('path'); var webpack = require('webpack'); module.exports = { entry: ['./src/index.ts'], output: { filename: 'build.js', path: path.join(__dirname, 'dist') }, resolve: { extensions: ['.ts', '.js', '.json'] }, resolveLoader: { modules: ['node_modules'] }, devtool: 'inline-source-map', devServer: { proxy: [ { context: ['/api-v1/**', '/api-v2/**'], target: 'https://other-server.example.com', secure: false } ] }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html', inject: 'body', hash: true }), new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', 'window.jquery': 'jquery' }) ], module:{ loaders: loaders } };
Loaders are just the usual stuff included.
Using Watch Mode You can instruct webpack to "watch" all files within your dependency graph for changes. If one of these files is updated, the code will be recompiled so you don't have to run the full build manually. Now run npm run watch from the command line and see how webpack compiles your code.
Other Ways to Enable Watch Mode You can also enable watch mode from your Webpack config file: module. exports = { mode: 'development', watch: true, // Enable watch mode entry: { app: `${__dirname}/app. js` }, target: 'web', output: { path: `${__dirname}/bin`, filename: '[name].
Exists only in webpack-dev-server. It's only needed if you want to serve static files. For example, you want a folder of mp4 vacation movies to be available for the app, but you don't want to run them through the bundle, because that would be silly.
You can config in in webpack.config file or in WebpackDevServer option, to watch for changes also in node_modules (i think that by default webpack watching for changes in all files)
https://webpack.js.org/configuration/watch/#watchoptions-ignored
in the following example webpack ignored all changes in node_modules folder except specific module.
watchOptions: { ignored: [ /node_modules([\\]+|\/)+(?!some_npm_module_name)/, /\some_npm_module_name([\\]+|\/)node_modules/ ] }
ignored[0]
= Regex to ignore all node_modules that not started with some_npm_module_name
ignored[1]
= Regex to ignore all node_modules inside some_npm_module_name
You may also used this link npm linked modules don’t find their dependencies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With