Skip to content

Commit

Permalink
进入polakdot dapp判断
Browse files Browse the repository at this point in the history
webpack打包的问题
  • Loading branch information
fengweiqiang-coder committed Mar 24, 2021
1 parent 83a930f commit d55e786
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 295 deletions.
116 changes: 3 additions & 113 deletions .electron-vue/webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let rendererConfig = {
polkadotdapp: path.join(__dirname, '../src/api/polkadotdapp.js'),
ethereumdapp: path.join(__dirname, '../src/api/ethereumdapp.js'),
ethereumdapp_imkey_web3: path.join(__dirname, '../src/api/ethereumdapp_imkey_web3.js'),
imkey_web3_provider: path.join(__dirname, '../src/api/imkey_web3_provider.js')
// imkey_web3_provider: path.join(__dirname, '../src/api/imkey_web3_provider.js')
},
externals: [
...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
Expand Down Expand Up @@ -118,18 +118,6 @@ let rendererConfig = {
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
// new HtmlWebpackPlugin({
// filename: 'index.html',
// template: path.resolve(__dirname, '../src/index.ejs'),
// minify: {
// collapseWhitespace: true,
// removeAttributeQuotes: true,
// removeComments: true
// },
// nodeModules: process..env.NODE_ENV !== 'production'
// ? path.resolve(__dirname, '../node_modules')
// : false
// }),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
Expand Down Expand Up @@ -180,106 +168,6 @@ let rendererConfig = {
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'polkadotdapp.html',
template: path.resolve(__dirname, '../src/polkadotdapp.ejs'),
chunks: ['polkadotdapp', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'ethereumdapp_imkey_web3.html',
template: path.resolve(__dirname, '../src/ethereumdapp_imkey_web3.ejs'),
chunks: ['ethereumdapp_imkey_web3', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'imkey_web3_provider.html',
template: path.resolve(__dirname, '../src/imkey_web3_provider.ejs'),
chunks: ['imkey_web3_provider', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'ethereumdapp.html',
template: path.resolve(__dirname, '../src/ethereumdapp.ejs'),
chunks: ['ethereumdapp', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
Expand Down Expand Up @@ -324,6 +212,8 @@ if (process.env.NODE_ENV === 'production') {
patterns: [
{ from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/electron/static')},
{ from: path.join(__dirname, '../src/api/imkey_web3_provider.js'),
to: path.join(__dirname, '../dist/electron/imkey_web3_provider.js')},
]
}),
new webpack.DefinePlugin({
Expand Down
89 changes: 3 additions & 86 deletions .electron-vue/webpack.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let webConfig = {
worker: path.join(__dirname, '../src/worker/worker.js'),
polkadotdapp: path.join(__dirname, '../src/api/polkadotdapp.js'),
ethereumdapp: path.join(__dirname, '../src/api/ethereumdapp.js'),
imkey_web3_provider: path.join(__dirname, '../src/api/imkey_web3_provider.js')
// imkey_web3_provider: path.join(__dirname, '../src/api/imkey_web3_provider.js')
},
module: {
rules: [
Expand Down Expand Up @@ -89,16 +89,6 @@ let webConfig = {
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({filename: 'styles.css'}),
// new HtmlWebpackPlugin({
// filename: 'index.html',
// template: path.resolve(__dirname, '../src/index.ejs'),
// minify: {
// collapseWhitespace: true,
// removeAttributeQuotes: true,
// removeComments: true
// },
// nodeModules: false
// }),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
Expand Down Expand Up @@ -150,81 +140,6 @@ let webConfig = {
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'polkadotdapp.html',
template: path.resolve(__dirname, '../src/polkadotdapp.ejs'),
chunks: ['polkadotdapp', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'imkey_web3_provider.html',
template: path.resolve(__dirname, '../src/imkey_web3_provider.ejs'),
chunks: ['imkey_web3_provider', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new HtmlWebpackPlugin({
filename: 'ethereumdapp.html',
template: path.resolve(__dirname, '../src/ethereumdapp.ejs'),
chunks: ['ethereumdapp', 'vendor'],
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
Expand Down Expand Up @@ -256,6 +171,8 @@ if (process.env.NODE_ENV === 'production') {
patterns: [
{ from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/web/static')},
{ from: path.join(__dirname, '../src/api/imkey_web3_provider.js'),
to: path.join(__dirname, '../dist/electron/imkey_web3_provider.js')},
]
}),
new webpack.DefinePlugin({
Expand Down
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ test/unit/*.js
test/e2e/*.js
src/proto/**
src/api/devicemanagerapi.js
src/api/walletapi.js
src/api/walletapi.js
src/api/imkey_web3_provider.js
16 changes: 7 additions & 9 deletions src/api/ethereumdapp_imkey_web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
// const ImKeyProvider = require('/Users/xyz/Code/imkey-web3-provider/dist/index').default
const { contextBridge, ipcRenderer } = require('electron')


// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
'imKeyManager',
{
accounts: () => {
const res = ipcRenderer.sendSync('message-from-get-address')
const walletAddressArray = res.result
for (let i = 0; i < walletAddressArray.length; i++) {
if (walletAddressArray[i].chain === 'Ethereum') {
return [walletAddressArray[i].address]
}
const res = ipcRenderer.sendSync('message-from-get-address')
const walletAddressArray = res.result
for (let i = 0; i < walletAddressArray.length; i++) {
if (walletAddressArray[i].chain === 'Ethereum') {
return [walletAddressArray[i].address]
}
}
},
callNativeApi: async (data) => {
// return await ipcRenderer.invoke('imkey-api', data)
Expand All @@ -40,7 +39,7 @@ contextBridge.exposeInMainWorld(
// };

const scriptContent = ipcRenderer.sendSync('read-file')
// console.log(scriptContent)
console.log(scriptContent)
// let pathToInjectScript = `file://${imkeyWeb3ProviderSrc}`

// window.accounts = store.accounts;
Expand All @@ -67,7 +66,6 @@ process.on('document-start', () => {
// document.documentElement.appendChild(script);
// })


// document.addEventListener(
// "DOMContentLoaded",
// function() {
Expand Down
7 changes: 2 additions & 5 deletions src/api/polkadotdapp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {
web3Enable,
web3Accounts
web3Enable
} = require('@polkadot/extension-dapp')

const { Decimal } = require('decimal.js')
Expand Down Expand Up @@ -163,8 +162,6 @@ function getAddress () {
genesisHash: PolkadotGenesisHash
}])
}
// const accounts =[{ address: 'J7Jnbiv5EZSTcD5qf2UdFcZVUY3x3S5r1VXNU3avaP4pqwE', name: 'Menglong', genesisHash: KusamaGenesisHash }]

const accounts = getAddress()

window.injectedWeb3 = {
Expand Down Expand Up @@ -200,7 +197,7 @@ web3Enable('imkey')

// returns an array of { address, meta: { name, source } }
// meta.source contains the name of the extension that provides this account
const allAccounts = web3Accounts()
// const allAccounts = web3Accounts()

// the address we use to use for signing, as injected
// const SENDER = '5DgzZQE9FS7G5CJLrLgVq2YNa4LM3oYdPh4DFfpp4cMRcWeM'
Expand Down
Loading

0 comments on commit d55e786

Please sign in to comment.