Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ea6cf9

Browse files
committedMay 22, 2021
Adapt code to new default project structure
Closes #3
1 parent 9acd062 commit 0ea6cf9

File tree

7 files changed

+1073
-2226
lines changed

7 files changed

+1073
-2226
lines changed
 

‎dfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dfinity_vue"
1010
],
1111
"frontend": {
12-
"entrypoint": "src/dfinity_vue_assets/public/index.js"
12+
"entrypoint": "src/dfinity_vue_assets/src/index.html"
1313
},
1414
"source": [
1515
"src/dfinity_vue_assets/assets",

‎package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
"build": "webpack"
88
},
99
"devDependencies": {
10-
"@dfinity/agent": "0.6.14",
10+
"@dfinity/agent": "0.8.8",
11+
"assert": "2.0.0",
12+
"buffer": "6.0.3",
13+
"events": "3.3.0",
1114
"terser-webpack-plugin": "2.2.2",
15+
"html-webpack-plugin": "5.3.1",
16+
"process": "0.11.10",
17+
"stream-browserify": "3.0.0",
18+
"util": "0.12.3",
1219
"vue-loader": "^15.9.5",
1320
"vue-template-compiler": "^2.6.12",
14-
"webpack": "4.41.3",
15-
"webpack-cli": "3.3.10"
21+
"webpack": "5.24.4",
22+
"webpack-cli": "4.5.0"
1623
},
1724
"dependencies": {
1825
"vue": "^2.6.12"

‎src/dfinity_vue_assets/public/App.vue renamed to ‎src/dfinity_vue_assets/src/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
</template>
66

77
<script>
8-
import dfinity_vue from 'ic:canisters/dfinity_vue';
8+
import { Actor, HttpAgent } from '@dfinity/agent';
9+
import { idlFactory as dfinity_vue_idl, canisterId as dfinity_vue_id } from 'dfx-generated/dfinity_vue';
910
1011
export default {
1112
data: () => {
@@ -14,6 +15,9 @@ export default {
1415
};
1516
},
1617
created() {
18+
const agent = new HttpAgent();
19+
const dfinity_vue = Actor.createActor(dfinity_vue_idl, { agent, canisterId: dfinity_vue_id });
20+
1721
dfinity_vue.greet(window.prompt("Enter your name:")).then(greeting => {
1822
this.internetComputerGreeting = greeting
1923
});

‎src/dfinity_vue_assets/src/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title><%= htmlWebpackPlugin.options.title %></title>
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
</body>
10+
</html>

‎webpack.config.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const path = require("path");
2+
const webpack = require("webpack");
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
24
const TerserPlugin = require("terser-webpack-plugin");
35
const { VueLoaderPlugin } = require("vue-loader");
46
const dfxJson = require("./dfx.json");
57

68
// List of all aliases for canisters. This creates the module alias for
7-
// the `import ... from "ic:canisters/xyz"` where xyz is the name of a
9+
// the `import ... from "@dfinity/ic/canisters/xyz"` where xyz is the name of a
810
// canister.
911
const aliases = Object.entries(dfxJson.canisters).reduce(
1012
(acc, [name, _value]) => {
@@ -20,8 +22,7 @@ const aliases = Object.entries(dfxJson.canisters).reduce(
2022

2123
return {
2224
...acc,
23-
["ic:canisters/" + name]: path.join(outputRoot, name + ".js"),
24-
["ic:idl/" + name]: path.join(outputRoot, name + ".did.js"),
25+
["dfx-generated/" + name]: path.join(outputRoot, name + ".js"),
2526
};
2627
},
2728
{}
@@ -38,33 +39,46 @@ function generateWebpackConfigForCanister(name, info, env) {
3839
return {
3940
mode: env.development ? "development" : "production",
4041
entry: {
41-
index: path.join(__dirname, info.frontend.entrypoint),
42+
// The frontend.entrypoint points to the HTML file for this build, so we need
43+
// to replace the extension to `.js`.
44+
index: path.join(__dirname, info.frontend.entrypoint).replace(/\.html$/, ".js"),
4245
},
43-
devtool: env.development ? "source-map" : "",
46+
devtool: env.development ? "inline-source-map" : false,
4447
optimization: {
4548
minimize: true,
4649
minimizer: [new TerserPlugin()],
4750
},
4851
resolve: {
4952
alias: aliases,
53+
extensions: [".js", ".ts", ".jsx", ".tsx"],
54+
fallback: {
55+
"assert": require.resolve("assert/"),
56+
"buffer": require.resolve("buffer/"),
57+
"events": require.resolve("events/"),
58+
"stream": require.resolve("stream-browserify/"),
59+
"util": require.resolve("util/"),
60+
},
5061
},
5162
output: {
5263
filename: "[name].js",
5364
path: path.join(__dirname, "dist", name),
5465
},
55-
56-
// Depending in the language or framework you are using for
57-
// front-end development, add module loaders to the default
58-
// webpack configuration. For example, if you are using React
59-
// modules and CSS as described in the "Adding a stylesheet"
60-
// tutorial, uncomment the following lines:
6166
module: {
6267
rules: [
6368
{ test: /\.vue$/, loader: "vue-loader" }
6469
]
6570
},
6671
plugins: [
67-
new VueLoaderPlugin()
72+
new VueLoaderPlugin(),
73+
new HtmlWebpackPlugin({
74+
template: path.join(__dirname, info.frontend.entrypoint),
75+
filename: 'index.html',
76+
chunks: ['index'],
77+
}),
78+
new webpack.ProvidePlugin({
79+
Buffer: [require.resolve('buffer/'), 'Buffer'],
80+
process: require.resolve('process/browser'),
81+
}),
6882
],
6983
};
7084
}

0 commit comments

Comments
 (0)
Please sign in to comment.