I have webpack set up with a plug-in handling application files & css.
webpack.config.js
const path = require('path');
const glob = require('glob');
const uglify = require("uglify-js");
const cleanCSS = require("clean-css");
const merge = require('webpack-merge-and-include-globally');
const mode = 'dev';
const ext = mode === 'prod' ? '.min' : '';
module.exports = (event, arg) => {
let config = {
mode: mode === 'dev' ? 'development' : 'prod' ? 'production' : '',
entry: {
bundle : [ "./build/index.js" ]
},
output: {
path: __dirname + '/public',
filename: "js/[name].js"
},
plugins: [
new merge({
files: {
// concatenate angular app
'./app/app.js' : [
'./build/app/js/app.js',
'./build/app/js/controllers/*',
'./build/app/js/directives/*',
'./build/app/js/services/*',
],
// compile scripts & css
'./js/scripts.js' : [ './build/js/scripts.js' ],
'./css/style.css' : [ './build/css/*' ]
},
transform: { // minify in prod mode
'./app/app.js' : code => mode === 'prod' ? uglify.minify(code).code : code,
'./js/scripts.js' : code => mode === 'prod' ? uglify.minify(code).code : code,
'./css/style.css' : code => mode === 'prod' ? new cleanCSS({}).minify(code).styles : code
}
})
]
}
return config;
}
When I run npm run build
the script works as expected building a bundle.js
with my dependencies, an app.js
with my application, and a style.css
with my css.
However when I run npm run watch
webpack only watches the entry files for bundle.js
- index.js.
Is it possible to indicate that webpack watch entry files for the plugins as well? Or can I indicate that the build script is triggered on the changing of some arbitrary files?