Hey. I start working with Webpack and now my config looks like this:

'use strict'; var path = require("path"); module.exports = { entry: "./src/app.js", module: { loaders: [{ test: /.js$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['es2015'] } }] }, output: { path: path.resolve(__dirname, '../assets/js/'), filename: 'app.js' } }; 

In this case, the app.js file is taken from the /dev/src/ app.js , transported to ES5 using the babel-loader and sent to the /assets/js/app.js folder. But I still have the folder /dev/src/js-modules/ , which contains various js-modules that I downloaded from various sources. I don’t really like the require() ideology of Node modules, so I just want to collect all the js files from the /dev/src/js-modules/ folder into one file and send it along the path /assets/js/modules.js . How to do it?

    1 answer 1

    Hey.

    You can simply specify another entry point and explicitly list which scripts you need in it.

     entry: { app: "./src/app.js", modules: ["./src/js-modules/script1", "./src/js-modules/script1"] }, ... output: { path: path.resolve(__dirname, '../assets/js/'), filename: "[name].bundle.js", ...} 

    Read more here http://webpack.imtqy.com/docs/configuration.html#entry

    • This konfing will simply run all the files in /assets/js/ through the Webpack, but it will not collect them all into one file under the same name. - JamesJGoodwin
    • @JamesJGoodwin why not collect? I checked it myself - app.js and modules.js are created in which the bootstrap webpack and the scripts wrapped in the webpack modules. Or do you need to glue the scripts "as is"? - chromigo
    • Can't you just go through the js-modules folder with a regular file and collect all the files? For example, /.js$/ - JamesJGoodwin
    • The @JamesJGoodwin webpack is primarily a modular build system. Those. as a result, all your scripts will become modules available for downloading through require / import. If you do not need this, you can use simpler technologies, such as gulp. There, the task of assembling a frontend is described in a similar way. There you can simply glue all the scripts into 1 file, minify it and so on. - chromigo
    • @JamesJGoodwin may have already seen, but just in case I will leave links here about the galp learn.javascript.ru/screencast/gulp about webpack learn.javascript.ru/screencast/webpack - chromigo