A
A
Alsu Sh2019-09-21 19:42:15
Express.js
Alsu Sh, 2019-09-21 19:42:15

How to configure webpack+express configuration so that only one js file is generated during the build, but several css files?

There is a webpack setting with express js, I wrote two files in entry in order to generate several css files for production, but at startup (npm start), the second super.min.js file is also formed, and you only need style.min.css and super.min.css. Please tell me what needs to be corrected. Also, for some reason, the minified js file weighs a lot, which may be connected with it. Thanks everyone for the replies. 5d8651b36d4c6241597848.png
package.json like this:
{
"name": "chessapp",
"version": "0.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts" : {
"start": "webpack -d --watch ",
"dev-server"
},
"author": "ALsuSh",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5. 5",
"@babel/preset-react": "^7.0.0",
"autoprefixer": "^9.6.1",
"babel-loader": "^8.0.6",
"copy-webpack-plugin" : "^5.0.4",
"css-loader": "^3.1.0",
"css-mqpacker": "^7.0.0",
"cssnano": "^4.1.10",
"file-loader" : "^4.1.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.12.0",
"path": "^0.12.7",
"postcss-loader": "^3.0 .0",
"react-hot-loader": "^4.12.13",
} } and webpack.config.js: const path = require("path"); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
// Main const
const PATHS = {
src: path.join(__dirname, './src'),
public: path.join(__dirname, './public'),
};
module.exports = {
mode: 'development',
externals: {
paths: PATHS
},
entry: {
app : './src/index.js',
super : './src/super.js',
},
devtool: 'inline-source-map',
devServer : {
contentBase: './public'
},
output: {
filename: "js/[name].min.js",
path: PATHS.public,
},
module: {
rules: [
{
test: /\.(js|jsx)?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
},
}
,{
test: /\.scss $/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { sourceMap: true }
}, {
loader: 'postcss-loader',
options: { sourceMap: true, config: { path: `./postcss.config.js` } }
}, {
loader: 'sass-loader',
options: { sourceMap: true }
}
]
},
{
test: /\ .css$/,
use: ['style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { sourceMap: true }
}, {
loader: 'postcss-loader',
options: { sourceMap: true, config: { path: `./postcss.config.js` } }
}]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "css/[name].min.css",
}),
/* new webpack.HotModuleReplacementPlugin({
multiStep: true
}),
new CopyWebpackPlugin([
{ from: `${PATHS.src}/${PATHS.assets}img`, to: `${PATHS.assets} img` },
{ from: `${PATHS.src}/static`, to: '' },
]),
new HtmlWebpackPlugin({
template: `${PATHS.src}/index.html`
})*/
]
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question