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

ReferenceError: require is not defined #211

Closed
biubiupiu320 opened this issue Jun 21, 2022 · 1 comment
Closed

ReferenceError: require is not defined #211

biubiupiu320 opened this issue Jun 21, 2022 · 1 comment

Comments

@biubiupiu320
Copy link

The following error occurs when I use screenfull.js(import screenfull from "screenfull") in a Vue component, what should I do, help me please.
image

version:
vue: 2.6.14
@vue/cli-service: 5.0.4
babel-loader: 8.2.5
vue-loader: 17.0.0
webpack: 5.73.0
eslint: 7.32.0

config:
babel.config.js

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  env: {
    development: {
      plugins: ['dynamic-import-node']
    }
  },
  plugins: ['lodash']
}

vue.config.js

const {defineConfig} = require('@vue/cli-service')
const path = require('path')
const webpack = require('webpack')

function resolve(dir) {
  return path.join(__dirname, dir)
}

const name = process.env.VUE_APP_TITLE || 'hello'

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: process.env.NODE_ENV === 'development' ? '/' : '/',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV !== 'production',
  productionSourceMap: false,
  configureWebpack: {
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    plugins: [
      new webpack.IgnorePlugin({
        resourceRegExp: /\.\/locale/,
        contextRegExp: /moment/
      })
    ]
  },
  chainWebpack(config) {
    config.plugins.delete('preload')
    config.plugins.delete('prefetch')

    // set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/assets/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()

    config.when(process.env.NODE_ENV !== 'development', config => {
      config.optimization.splitChunks({
        chunks: 'all',
        cacheGroups: {
          libs: {
            name: 'chunk-libs',
            test: /[\\/]node_modules[\\/]/,
            priority: 10,
            chunks: 'initial' // only package third parties that are initially dependent
          },
          elementUI: {
            chunks: 'all',
            name: 'chunk-elementUI', // split elementUI into a single package
            priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
            test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
          },
          commons: {
            chunks: 'all',
            name: 'chunk-commons',
            test: resolve('src/components'), // can customize your rules
            minChunks: 3, //  minimum common number
            priority: 5,
            reuseExistingChunk: true
          },
          echarts: {
            chunks: 'all',
            test: /echarts/,
            name: 'echarts',
            enforce: true
          },
          lodash: {
            chunks: 'all',
            test: /lodash/,
            name: 'lodash',
            enforce: true
          },
          fabric: {
            chunks: 'all',
            test: /fabric/,
            name: 'fabric',
            enforce: true
          }
        }
      })
    })
  }
})
@sindresorhus
Copy link
Owner

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

2 participants