Set publicPath in prod webpack config

This commit is contained in:
Bruno Alla 2022-03-19 13:00:33 +00:00
parent 7afad7484f
commit ab78c56319
3 changed files with 22 additions and 6 deletions

View File

@ -13,7 +13,7 @@ module.exports = {
path: path.resolve(__dirname, '../{{cookiecutter.project_slug}}/static/webpack_bundles/'), path: path.resolve(__dirname, '../{{cookiecutter.project_slug}}/static/webpack_bundles/'),
publicPath: '/static/webpack_bundles/', publicPath: '/static/webpack_bundles/',
filename: 'js/[name]-[fullhash].js', filename: 'js/[name]-[fullhash].js',
chunkFilename: 'js/[name]-[hash].js' chunkFilename: 'js/[name]-[hash].js',
}, },
plugins: [ plugins: [
new BundleTracker({filename: path.resolve(__dirname, '../webpack-stats.json')}), new BundleTracker({filename: path.resolve(__dirname, '../webpack-stats.json')}),
@ -45,11 +45,11 @@ module.exports = {
}, },
'sass-loader', 'sass-loader',
], ],
} },
], ],
}, },
resolve: { resolve: {
modules: ['node_modules'], modules: ['node_modules'],
extensions: ['.js', '.jsx'] extensions: ['.js', '.jsx'],
}, },
} };

View File

@ -17,4 +17,4 @@ module.exports = merge(commonConfig, {
hot: false, hot: false,
liveReload: true, liveReload: true,
}, },
}) });

View File

@ -1,8 +1,24 @@
const { merge } = require('webpack-merge'); const { merge } = require('webpack-merge');
const commonConfig = require('./common.config'); const commonConfig = require('./common.config');
// This variable should mirror the one from config/settings/production.py
{%- if cookiecutter.use_whitenoise == 'n' and cookiecutter.cloud_provider == 'AWS' %}
const s3BucketName = process.env.DJANGO_AWS_STORAGE_BUCKET_NAME;
const awsS3Domain = process.env.DJANGO_AWS_S3_CUSTOM_DOMAIN ?
process.env.DJANGO_AWS_S3_CUSTOM_DOMAIN
: `${s3BucketName}.s3.amazonaws.com`;
const staticUrl = `https://${awsS3Domain}/static/`;
{%- elif cookiecutter.use_whitenoise == 'n' and cookiecutter.cloud_provider == 'GCP' %}
const staticUrl = `https://storage.googleapis.com/${process.env.DJANGO_GCP_STORAGE_BUCKET_NAME}/static/`;
{%- else %}
const staticUrl = '/static/';
{%- endif %}
module.exports = merge(commonConfig, { module.exports = merge(commonConfig, {
mode: 'production', mode: 'production',
devtool: 'source-map', devtool: 'source-map',
bail: true, bail: true,
}) output: {
publicPath: `${staticUrl}webpack_bundles/`,
},
});