webpack: split configs into prod/dev

This commit is contained in:
dogeystamp 2023-01-30 21:37:04 -05:00
parent 63fa42e1e3
commit f6d07eb657
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
6 changed files with 36 additions and 21 deletions

View File

@ -1,6 +1,7 @@
env:
browser: true
es2021: true
node: true
extends: eslint:recommended
overrides: []
parserOptions:

3
package-lock.json generated
View File

@ -16,7 +16,8 @@
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
}
},
"node_modules/@discoveryjs/json-ext": {

View File

@ -5,9 +5,9 @@
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"lint": "eslint --ext .js,.jsx src",
"start": "webpack serve --open"
"build": "webpack --config webpack.prod.js",
"lint": "eslint --ext .js,.jsx src *.js",
"start": "webpack serve --open --config webpack.dev.js"
},
"repository": {
"type": "git",
@ -40,6 +40,7 @@
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
}
}

View File

@ -1,19 +1,14 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const pages = ["index", "aes"];
module.exports = {
mode: 'development',
entry: pages.reduce((config, page) => {
config[page] = `./src/${page}.js`;
return config;
}, {}),
devtool: 'inline-source-map',
devServer: {
static: './dist',
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
@ -30,21 +25,21 @@ module.exports = {
chunkFilename: "[id].[contenthash].css",
}),
].concat(
pages.map(
(page) =>
new HtmlWebpackPlugin({
inject: true,
template: `./src/pages/${page}.html`,
filename: `${page}.html`,
chunks: [page],
})
pages.map(
(page) =>
new HtmlWebpackPlugin({
inject: true,
template: `./src/pages/${page}.html`,
filename: `${page}.html`,
chunks: [page],
})
)
),
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},

10
webpack.dev.js Normal file
View File

@ -0,0 +1,10 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
devServer: {
static: "./dist",
},
});

7
webpack.prod.js Normal file
View File

@ -0,0 +1,7 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "production",
devtool: "source-map",
});