Answer the question
In order to leave comments, you need to log in
How to configure webpack to get two kinds of files as output?
Now my webpack is configured like this:
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isDev = process.env.NODE_ENV === 'development';
module.exports = {
mode: process.env.NODE_ENV,
entry: './source/index.ts',
devtool: isDev && 'inline-source-map',
watch: true,
resolve: {
extensions: ['.ts', '.js']
},
output: {
filename: isDev ? 'bundle.js' : 'bundle.min.js',
path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isDev,
},
},
'css-loader',
'postcss-loader',
'sass-loader',
]
},
]
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: isDev ? 'styles.css' : 'styles.min.css',
}),
]
}
Answer the question
In order to leave comments, you need to log in
Try to perform a single build without compression and source maps, and then run the necessary bundles through the standalone versions of the minifiers (that is, after the build is finished, outside of it). For example, using this https://www.npmjs.com/package/webpack-shell-plugin
Or export not one config, but an array of two from the webpack config file: https://webpack.js.org/configuration/configuration ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question