Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support with Next.JS #68

Open
ermauliks opened this issue Jan 13, 2021 · 4 comments
Open

Support with Next.JS #68

ermauliks opened this issue Jan 13, 2021 · 4 comments

Comments

@ermauliks
Copy link

Hello, I'm trying to integrate this webpack plugin with my Next.JS web application. Following is my next.config.js. It works in the production mode but not in the development mode.

Did anyone successfully integrate this plugin with the Next.JS?

const HtmlWebpackPlugin = require('html-webpack-plugin');
const DynamicCdnWebpackPlugin = require("dynamic-cdn-webpack-plugin");

module.exports = withPlugins([withTM], {
  webpack: (config, options) => {
    if (!options.isServer) {
      config.plugins.push(
        new DynamicCdnWebpackPlugin({
          only: ['react', 'react-dom']
        }),
      )
    return config;
  }
})
@mspinelli
Copy link

mspinelli commented May 6, 2021

I'm also curious about if there are issues with this working with Nuxt.JS (Vue's version of Nuxt.JS). The following config doesn't seem to use the cdn to load the two apexcharts packages (and still distributes them). Do I need to move them from dependencies to devDependencies?

  // nuxt.config.js
  ...
  build: {
    plugins: [
      new HtmlWebpackPlugin(),
      new DynamicCdnWebpackPlugin({
        only: [
          'vue-apexcharts',
          'apexcharts'
        ]
      })     
    ]
  }
  ...
  // package.json
  ...
  "dependencies": {
    "apexcharts": "^3.26.0",
    "core-js": "^3.9.1",
    "nuxt": "^2.15.3",
    "vue-apexcharts": "^1.6.1",
  },
  ...

@aulisius
Copy link
Collaborator

aulisius commented May 6, 2021

@mspinelli the default cdn resolver might not have those packages. I'm a bit caught up with stuff this week but I'll try to look into this next week.

@mspinelli
Copy link

mspinelli commented May 6, 2021

@mspinelli the default cdn resolver might not have those packages. I'm a bit caught up with stuff this week but I'll try to look into this next week.

@aulisius Correct and thanks! I ended up doing this (and turning verbose on showed that being the issue).

I also needed to do this:

    plugins: [
      new DynamicCdnWebpackPlugin({
        verbose: true,
        env: 'production',
        resolver: (packageName, packageVersion) => {
          return {
            name: packageName,
            var: packageName.replace('@', ''),
            version: packageVersion,
            url: `https://cdn.jsdelivr.net/npm/${packageName}@${packageVersion}/dist/${packageName}.min.js`
          }
        },
        only: [
          'vue-apexcharts',
          'apexcharts'
        ]
      })

@cuongdevjs
Copy link

cuongdevjs commented Oct 7, 2021

any update for nextjs. I config on next.config.js but it does not work, when I run my web throw error:

external "React":1 Uncaught ReferenceError: React is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants