rykener / django-manifest-loader

Simplifies webpack configuration with Django
https://django-manifest-loader.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
104 stars 12 forks source link

Issue with webpack-stats #39

Closed iwalucas closed 3 years ago

iwalucas commented 3 years ago

First, great project!

For some reason, the manifest is not picking correctly the URL from my webpack-stats:


{
    "status": "done",
    "publicPath": "http://localhost:8080/",
    "chunks": {
        "page1": [
            {
                "name": "js/page1.js",
                "publicPath": "http://localhost:8080/js/page1.js",
                "path": "/Users/xxx/frontend/dist/js/page1.js"
            }
        ],
        "page2": [
            {
                "name": "js/page2.js",
                "publicPath": "http://localhost:8080/js/page2.js",
                "path": "/Users/xxx/frontend/dist/js/page2.js"
            }
        ]
    }
}```

Its generating a `/static/page1.js`

I tried with `{%manifest 'page1.js'%}` and `{%manifest 'page1'%}` , both generate the same.
rykener commented 3 years ago

@iwalucas can you post your full webpack config + the generated manifest file?

iwalucas commented 3 years ago

I am using vue-cli... here is the config file

const BundleTracker = require("webpack-bundle-tracker");
module.exports = {
    publicPath: process.env.NODE_ENV === 'production'
    ? 'https://mycoolurl/static/'
    : 'http://localhost:8080',
    outputDir: './dist/',
    chainWebpack: config => {
        config.optimization
            .splitChunks(false)
        config
            .plugin('BundleTracker')
            .use(BundleTracker, [{filename: '../frontend/webpack-stats.json'}])
        config.resolve.alias
            .set('__STATIC__', 'static')
        config.devServer
            .public('http://0.0.0.0:8080')
            .host('0.0.0.0')
            .port(8080)
            .hotOnly(true)
            .watchOptions({poll: 1000})
            .https(false)
            .headers({"Access-Control-Allow-Origin": ["\*"]})
    },
    pages: {
        page1: 'src/page1.js',
        page2:'src/page2.js'
    }
};

the manifest is the webpack-stats?

rykener commented 3 years ago

@iwalucas You're on the right track with the vue config you have. The plugin you're using to generate the manifest file (in your case "webpack-stats") is not the plugin that works with django-manifest-loader out of the box.

1) If your manifest file is not named manifest.json then you need to let Django Manifest Loader know about that in the settings 2) If you want to use the webpack-bundle-tracker plugin to generate your manifest file, then you'll need to write a custom loader to parse through it. Details are in the docs. 3) In order to get up and running without having to do the above, you need to use webpack-manifest-plugin to generate your manifest file.

happy to answer any questions you have about that