参考:vue组件中未定义require
当我在vue组件中使用screetfull.js(incortfull')时,会发生以下错误,我该怎么办,请帮助我。 错误信息
vue:2.6.14
@vue/vue/vue/cli - 服务:5.0.4
babel-loader:8.2.5
vue-loader:17.0.0
webpack:5.73.0
eslint:7.32.0
config:
babel.config.config.js
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
env: {
development: {
plugins: ['dynamic-import-node']
}
},
plugins: ['lodash']
}
vue.config.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'
},
elementUI: {
chunks: 'all',
name: 'chunk-elementUI',
priority: 20,
test: /[\\/]node_modules[\\/]_?element-ui(.*)/
},
commons: {
chunks: 'all',
name: 'chunk-commons',
test: resolve('src/components'),
minChunks: 3,
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
}
}
})
})
}
})
The following error occurs when I use screenfull.js(import screenfull from "screenfull") in a Vue component, what should I do, help me please.
error info
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'
},
elementUI: {
chunks: 'all',
name: 'chunk-elementUI',
priority: 20,
test: /[\\/]node_modules[\\/]_?element-ui(.*)/
},
commons: {
chunks: 'all',
name: 'chunk-commons',
test: resolve('src/components'),
minChunks: 3,
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
}
}
})
})
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
vue.config.js
您有transpiledepentencies
已启用,尝试将其删除或排除包:In
vue.config.js
you havetranspileDependencies
enabled, try to remove it or exclude the package: