Closed Robotboy36 closed 1 week ago
"vite-plugin-static-copy": "^2.1.0"
不明所以
Please read the error message and the linked page.
"vite-plugin-static-copy" resolved to an ESM file. ESM file cannot be loaded by
require
. See https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.
试过了, 不行
import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path' import autoprefixer from 'autoprefixer' import ViteMpaPlugin from 'vite-plugin-multiple-entry'; import { viteStaticCopy } from 'vite-plugin-static-copy'
// https://vitejs.dev/config/ export default defineConfig(({ command, mode, ssrBuild }) => { console.log('构建环境', command, mode);
const config = {
base: mode === 'development' ? '/' : '/',
productionSourceMap: false,
integrity: true,
crossorigin: 'anonymous',
define: {
ENV: JSON.stringify(mode),
},
resolve: {
alias: {
'@': path.join(__dirname, './src')
}
},
plugins: [
vue(),
ViteMpaPlugin(),
viteStaticCopy({
targets: [
{
src: 'src/static/images/*', // 静态资源来源目录
dest: 'assets/images', // 输出目录,相对于 dist
}
]
}),
],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
},
postcss: {
plugins: [
autoprefixer({
overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8'],
}),
],
},
},
server: {
port: 8080,
strictPort: true,
hmr: true, // 开启热更新
},
build: {
outDir: path.join(__dirname, 'dist'),
target: 'es2015',
emptyOutDir: true,
chunkSizeWarningLimit: 500,
terserOptions: {
compress: {
drop_console: mode === 'production',
drop_debugger: mode === 'production',
},
},
},
};
return config;
})
I need a reproduction to answer it in that case.
[ERROR] "vite-plugin-static-copy" resolved to an ESM file. ESM file cannot be loaded by
require
. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]