We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const path = require('path'); const webpack = require('webpack'); const { MergeIntoSingleFilePlugin } = require('webpack-merge-and-include-globally'); module.exports = { entry: './src/index.ts', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, target: 'node', mode: 'production', resolve: { extensions: ['.ts', '.js'], }, module: { rules: [ { test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/, }, ], }, plugins: [ new MergeIntoSingleFilePlugin({ files: { 'package.json': { transform: (content) => { const pkg = JSON.parse(content); pkg.dependencies = { ...pkg.dependencies, '@trustwallet/wallet-core': '^1.0.0', }; return JSON.stringify(pkg, null, 2); }, }, }, transform: (content, path) => { if (path.endsWith('.ts') || path.endsWith('.js')) { return `require(${JSON.stringify(path)});`; } return content; }, ignore: ['@trustwallet/wallet-core'], }), new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1, }), ], };
在使用webpack打包nodejs服务端代码时,如果遇到依赖底层c++模块的方法导致报错,可以采取以下几种处理方式:
externals: { 'my-cpp-module': 'commonjs my-cpp-module' }
// webpack.config.js const nodeExternals = require('webpack-node-externals'); module.exports = { // ... target: 'node', externals: [nodeExternals({ allowlist: ['my-cpp-module'] })], entry: { server: './src/server.js', cpp: './src/cpp.js' }, output: { // ... filename: '[name].js' } }; // server.js const myCppModule = require('./cpp'); // ... // cpp.js module.exports = require('my-cpp-module');
// webpack.config.js const nodeExternals = require('webpack-node-externals'); module.exports = { // ... target: 'node', externals: [nodeExternals()], // ... }; // server.js const myCppModule = require('my-cpp-module'); // ...
以上三种方式都可以解决依赖底层c++模块的报错问题,具体使用哪种方式取决于具体情况。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
在使用webpack打包nodejs服务端代码时,如果遇到依赖底层c++模块的方法导致报错,可以采取以下几种处理方式:
以上三种方式都可以解决依赖底层c++模块的报错问题,具体使用哪种方式取决于具体情况。
The text was updated successfully, but these errors were encountered: