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

how can i build js lib? #142

Open
weixuefeng opened this issue Nov 16, 2023 · 1 comment
Open

how can i build js lib? #142

weixuefeng opened this issue Nov 16, 2023 · 1 comment

Comments

@weixuefeng
Copy link

my js content is:

function testHello() {
    return "hello"
}

let myLib = {
    testHello
}

module.export = myLib

flutter content is:

 await initRuntime();
    var res = javascriptRuntime.evaluate("""
                testHello();
                """).stringResult;

it's works.

but when i build it with webpack,

const path = require('path')

module.exports = {
  entry: ['./src/main.js'],
  // devtool: 'source-map',
  mode: 'production',
  resolve: {
    extensions: ['.tsx', '.ts', '.js']
  },
  output: {
    filename: 'vara-network.min.js',
    path: path.resolve(__dirname, 'dist'),
    globalObject: "this",
    library: 'varaNetwork',
    libraryTarget: 'umd'
  }
};
build: npx webpack --config webpack.config.js
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.varaNetwork=t():e.varaNetwork=t()}(this,(()=>(()=>{var e={225:(e,t,o)=>{(e=o.nmd(e)).export={testHello:function(){return"hello"}}}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var d=t[r]={id:r,loaded:!1,exports:{}};return e[r](d,d.exports,o),d.loaded=!0,d.exports}return o.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),o(225)})()));

it can not works. and got error:

address is:"ERROR: Can't find variable: testHello \n  at global code@"
@stonesong
Copy link

stonesong commented Mar 1, 2024

Found a solution using:
libraryTarget: 'var', globalObject: 'this',

in the webpack config

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