Skip to content

Commit

Permalink
Fix assets path rewriting in webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-fazzi committed Apr 28, 2023
1 parent 1927687 commit 810f3f6
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions wordless/theme_builder/vanilla_theme/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const path = require('path');
const srcDir = path.resolve(__dirname, 'src');
const dstDir = path.resolve(__dirname, 'dist');
const javascriptsDstPath = path.join(dstDir, '/javascripts');
const _stylesheetsDstPath = path.join(dstDir, '/stylesheets');

const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const wordpressDir = path.resolve('../../../');
const imageFolderName = 'images'
const entries = ['main'];

Expand All @@ -26,15 +24,9 @@ module.exports = (env) => {
}, {}),

output: {
filename: "[name].js",
path: javascriptsDstPath,
publicPath: () => {
return path.join(
'/', // prepend slash to make an absolute web path
path.relative(wordpressDir, dstDir) // dist folder relative to wordpress folder. Will be
// something like `wp-content/theme/themeName/dist`
)
}
filename: "javascripts/[name].js",
path: dstDir,
publicPath: '../'
},

devtool: envOptions.devtool,
Expand Down Expand Up @@ -73,7 +65,9 @@ module.exports = (env) => {
test: /\.(jpe?g|png|gif|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'dist/images/[name][ext]'
filename: (asset_obj) => {
return asset_obj.filename.replace('src/', '');
}
}
}
]
Expand All @@ -97,7 +91,7 @@ module.exports = (env) => {
}),

new MiniCssExtractPlugin({
filename: '../stylesheets/[name].css'
filename: 'stylesheets/[name].css'
}),

new CopyWebpackPlugin({
Expand All @@ -113,15 +107,6 @@ module.exports = (env) => {
].concat(envOptions.plugins),

optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: 'commons',
chunks: 'all',
minChunks: 2
}
}
},
minimizer: [
new ImageMinimizerPlugin({
minimizer: {
Expand Down

0 comments on commit 810f3f6

Please sign in to comment.