我正在构建一个svelte的web应用程序(它使用汇总)。我正在使用一个第三方SDK,它实现了这个API https://github.com/near/near-api-js。这个API在某个时候导入JSON。因此,我不得不安装@rollup/plugin-json。
我将它导入我的rollup.config.js中,如下所示..。
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only';
import json from '@rollup/plugin-json';
const production = !process.env.ROLLUP_WATCH;
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
};
}
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'cjs',
name: 'app',
file: 'public/build/bundle.js',
},
plugins: [
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production
}
}),
// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
json(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};
在这里,我打电话给/Services/FluxProvider.js中的第三方SDK .
App.js的script标签上试过这个.调用SDK方法之一时的相同结果
export let name;
import FluxSdk from "@fluxprotocol/amm-sdk";
async function main() {
const sdk = new FluxSdk();
await sdk.connect();
console.log("Connected and ready to go!");
}
main();
这样做后,我得到以下错误..。
(!) Plugin node-resolve: preferring built-in module 'util' over local alternative at 'C:\Users\Ethan\node_modules\util\util.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning [!] (plugin commonjs) SyntaxError: Deleting local variable in strict mode (8:8) in C:\Users\Ethan\Desktop\AMM-test\node_modules\u3\lib\cache.js
我做了以下工作..。
。
我不知道为什么会这样,在问了几个人之后,他们也不确定。
重要注意:这个SDK在我的创建-反应-应用程序项目中工作得很好,但不是在svelte webpack或svelte汇总中。
欢迎任何想法/建议。
发布于 2021-03-29 06:20:56
我用webpack模板做了同样的尝试。
npx degit sveltejs/template-webpack svelte-app
它并没有指责这些错误,我怀疑汇总与webpack一起包装的fluxsdk并不友好。
使用webpack模板,没有错误,svelte似乎编译得很好。
重要注意事项:这个SDK在我的创建反应应用项目中非常好,但在svelte webpack或svelte汇总中没有。
CRA也使用webpack。
https://stackoverflow.com/questions/66248017
复制相似问题