0

Hey guys I'm using webpack-cdn-plugin to load assets from CDN, but I'm having issues with loading CSS assets. This is how my code looks:

{
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html',
            favicon: './src/assets/images/favicon.ico',
            filename: 'index.html',
        }),
        new HtmlWebpackPlugin({
            template: './src/services.html',
            favicon: './src/assets/images/favicon.ico',
            filename: 'services.html',
        }),
        new HtmlWebpackPlugin({
            template: './src/blocks.html',
            favicon: './src/assets/images/favicon.ico',
            filename: 'blocks.html',
        }),
        new WebpackCdnPlugin({
            modules: [{
                name: 'masonry-layout',
                var: 'Masonry',
                path: mode === 'production' ? 'dist/masonry.pkgd.min.js' : 'dist/masonry.pkgd.js',
            },
            {
                name: 'imagesloaded',
                var: 'imagesLoaded',
                path: mode === 'production' ? 'imagesloaded.pkgd.min.js' : 'imagesLoaded.pkgd.js',
            },
            {
                name: 'flickity',
                var: 'Flickity',
                path: mode === 'production' ? 'dist/flickity.pkgd.min.js' : 'dist/flickity.pkgd.js',
            }],
            prod: true,
            publicPath: '/node_modules',
        }),
    ],
}

Reading the docs this should generate <link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css"> in head, but it doesn't. Flickity package has both CSS and JS files in dist folder. I have also tried adding

{
    name: 'flickity',
    var: 'flickity',
    path: isProd ? 'dist/flickity.min.css' : 'dist/flickity.css',
}

but this just generates another script link. Does anyone have any ideas how to make it work?

Zvezdas1989
  • 1,445
  • 2
  • 16
  • 34
  • Can you look at flickity package and see how it's different than vue mentioned in their [readme](https://github.com/shirotech/webpack-cdn-plugin#cdn-extension-for-the-html-webpack-plugin)? I wonder if it's packaged differently. You could also add some `console.log`s to the plugin source when running. Looks like the logic is at https://github.com/shirotech/webpack-cdn-plugin/blob/master/module.js (maybe in a different place when consuming). – Juho Vepsäläinen May 08 '20 at 06:57
  • @JuhoVepsäläinen Ill give it a go – Zvezdas1989 May 08 '20 at 11:48

0 Answers0