How to collect separate styles / scripts in a project into one file (bundle.js / bundle.css) using a webpack?
The project contains styles and scripts for each application, which lie in a separate directory. Frontend folder:
âââ frontend â âââ common â âââ node_modules â âââ app1 â âââ app2 â âââ app3 â âââ ... â âââ webpack.config.js Each application folder has the same structure, but contains a different number of scripts, styles, templates, which are located on the same level:
âââ app â âââ static â â âââ app â â âââ css â â â âââ app.css â â âââ js â â âââ app-detail.js â â âââ settings.js â âââ templates â âââ app â âââ app__element-detail.html â âââ app.html â âââ app__periodic-table.html â âââ app__settings.html How to collect all these files in one?
With reference to styles, I saw a method with an extract-text-webpack-plugin , but in all examples the same script is shown - one entry point, the styles are imported into the script and are already being assembled from them.
I just need to make a bundle, I'll plug it in the base template.
A similar question can be asked about the assembly of all scripts, except for your own scripts, you need to include npm scripts in the assembly.
Please give advice
My webcam config https://jsfiddle.net/9qkwuru1/ .
'use strict'; const NODE_ENV = process.env.NODE_ENV || 'development'; const webpack = require('webpack'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); module.exports = { context: __dirname, entry: "./table/static/table/js/settings.js", output: { path: __dirname + "/common", filename: "bundle.js" }, watch: NODE_ENV == 'development', watchOptions: { aggregateTimeout: 100 }, devtool: NODE_ENV == 'development' ? 'source-map' : null, resolve: { moduleDirectories: ['node_modules'], extension: ['', '.js', '.styl'] }, resolveLoader: { moduleDirectories: ['node_modules'], moduleTemplates: ['*-loader'], extension: ['', '.js' ] }, module: { loaders: [{ test: /\.js$/, loader: 'babel', exclude: [ /(node_modules|bower_components)/ ], query: { presets: ['es2015'] } }, { test: /\.jade$/, loader: 'jade' }, { test: /\.css$/, loader: ExtractTextPlugin.extract({ fallbackLoader: "style-loader", loader: "css-loader" }) }, { test: /\.styl$/, loader: 'style!css!autoprefixer?browsers=last 2 version!stylus?resolve url' }, { test: /\.(png|jpg|svg)/, loader: 'file?name=[path][name].[ext]' }] }, plugins: [ new webpack.NoErrorsPlugin(), new webpack.DefinePlugin({ NODE_ENV: JSON.stringify(NODE_ENV) }), new webpack.ProvidePlugin({}), new ExtractTextPlugin({ filename: "bundle.css" }) ] }; if (NODE_ENV == 'production') { module.exports.plugins.push( new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false, drop_console: true, unsafe: true } }) ) }