Skip to content

Commit 150f5e5

Browse files
author
LinXi
committed
add test for external components
1 parent b922ec0 commit 150f5e5

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"eslint-plugin-promise": "^3.5.0",
5151
"eslint-plugin-standard": "^3.0.1",
5252
"file-loader": "^0.11.1",
53+
"iview-weapp": "^2.0.0",
5354
"jest": "^19.0.2",
5455
"mkdirp": "^0.5.1",
5556
"rimraf": "^2.6.1",

test/src/js/pages/index/index.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"usingComponents": {
3-
"index-component": "../../components/index-component/index-component"
3+
"index-component": "../../components/index-component/index-component",
4+
"i-alert": "../../components/iview-weapp/dist/alert/index"
45
}
56
}

test/src/js/pages/index/index.wxml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
<view class="usermotto">
88
<text class="user-motto">{{motto}}</text>
99
<view bindtap="goToSubList">go to subPackages</view>
10+
<i-alert type="success">
11+
An success prompt
12+
</i-alert>
1013
</view>
1114
</view>

test/webpack.config.babel.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,30 @@ export default {
3535
name: '[name].[ext]',
3636
}
3737
},
38+
{
39+
test: /\.(wxss|wxml|json|png)$/,
40+
include: /node_modules/,
41+
loader: 'file-loader',
42+
options: {
43+
useRelativePath: false,
44+
name: (filePath) => {
45+
const flag = 'node_modules/';
46+
const index = filePath.indexOf(flag);
47+
if (index !== -1) {
48+
const targetPath = filePath.substring(index + flag.length).split('.')[0];
49+
return `./components/${targetPath}.[ext]`;
50+
}
51+
return `[name].[ext]`;
52+
},
53+
}
54+
},
3855
],
3956
},
4057
plugins: [
4158
new WXAppWebpackPlugin({
4259
extensions: [`.${ext}`, '.js'],
60+
externalComponents: ['iview-weapp'],
61+
externalComponentsDirectory: '../../../node_modules/',
4362
}),
4463
],
4564
devtool: 'source-map',

0 commit comments

Comments
 (0)