Now I am using [email protected]. For some reason, I need to watch file change of my source code to run webpack's build, with vue-cli-service build --watch
.
Currently, I run another Node.js process to watch file change, of webpack's bundle. I really suffered from this terrible development experience.
When I used vue-cli 2.x, I actually run webpack()
, one native API of webpack, in build/build.js
, so I could use webpack().watch()
instead to run build and pass my own script as callback function. However in vue-cli 3.x, there's no way and no need to approach the webpack's native API, within my knowledge.
I wish to run my own script after webpack's every auto build, though I could not find any guidance in vue-cli's official document.
Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to.
vue-cli-service lintLints and fixes files. If no specific files are given, it lints all files in src and tests , as well as all JavaScript files in the root directory (these are most often config files such as babel. config. js or . eslintrc.
With your project open the command palette by using the menu item View > Command Palette or by using the keyboard shortcut Shift + CMD + P or Shift + CTRL + P on Windows. From there type Tasks and click on the Run Task command. This will examine your project and give you a list of the available scripts to run.
From my understanding - you have a Webpack plugin use case. Just like for example webpack-build-notifier sends a notification after a rebuild.
I am not a Webpack plugin author, but this is already working for me:
// vue.config.js
const ArbitraryCodeAfterReload = function(cb) {
this.apply = function(compiler) {
if (compiler.hooks && compiler.hooks.done) {
compiler.hooks.done.tap('webpack-arbitrary-code', cb);
}
};
};
const myCallback = function() {
console.log('Implementing alien intelligence');
};
const plugins = [];
const isDev = process.env.NODE_ENV === 'development';
if (isDev) {
plugins.push(new ArbitraryCodeAfterReload(myCallback));
}
module.exports = {
configureWebpack: {
plugins
}
};
If this is not the right compilation step - the Webpack documentation should somewhere have the right hook
for your use case.
Maybe there is already a plugin available which already does what you need...
Maybe this can help you. This is just an example. You only need to use &&
npm run start && npm run build
So after the npm run start script execute your npm run build script will run after the first one
Update you can use this package webpack-shell-plugin
const WebpackShellPlugin = require('webpack-shell-plugin');
new WebpackShellPlugin({
onBuildStart: [''],
onBuildEnd: ['']
})
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