Skip to content

Commit

Permalink
Improve webpack output
Browse files Browse the repository at this point in the history
  • Loading branch information
liamjohnston committed May 21, 2024
1 parent 95c06b0 commit 65d7cb0
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 2 deletions.
215 changes: 215 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"autoprefixer": "^10.4.13",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.3",
"cssnano": "^5.1.14",
"eslint": "^8.32.0",
Expand Down
8 changes: 6 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const outputPath = 'static/dist';

Expand All @@ -17,6 +18,9 @@ module.exports = (env, options) => {
filename: 'styles.css',
chunkFilename: '[name]-[id].css',
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.resolve(__dirname, outputPath)],
}),
];

// SVG sprites. Each directory will create a spritemap (spritesheet).
Expand Down Expand Up @@ -45,9 +49,9 @@ module.exports = (env, options) => {
output: {
// NOTE: this is a little different from usual Springload setup due to different directory structure of this site.
path: path.resolve(__dirname, outputPath),
publicPath: '/static/dist/', // For some reason this adds an extra `/dist/` layer in the output, but only for font files. TODO resolve.
publicPath: '/static/dist/',
filename: '[name].js', // No filename hashing, Django takes care of this
chunkFilename: '[id]-[chunkhash].js',
chunkFilename: '[name]-[chunkhash].js',
clean: true,
},
devServer: {
Expand Down

0 comments on commit 65d7cb0

Please sign in to comment.