Skip to content

Commit 3a4ff48

Browse files
committed
feat: add webapck config
1 parent 5eb5cb5 commit 3a4ff48

File tree

14 files changed

+193
-5
lines changed

14 files changed

+193
-5
lines changed

build/webpack.config.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const { VueLoaderPlugin } = require('vue-loader')
2+
const path = require('path')
3+
const HtmlWebpackPlugin = require('html-webpack-plugin')
4+
5+
const NODE_ENV = process.env.NODE_ENV
6+
7+
8+
const HOST = 'localhost'
9+
const PORT = 8081
10+
11+
module.exports = {
12+
mode: NODE_ENV,
13+
entry: {
14+
main: process.env.NODE_ENV === 'development' ? path.resolve(__dirname, '../example/index.js') : path.resolve(__dirname, '../src/index.js'),
15+
},
16+
output: {
17+
path: path.resolve(__dirname, '../package'),
18+
filename: 'vue-luck-draw.js', //打包之后生成的文件名,可以随意写。
19+
library: 'vue-luck-draw', // 指定类库名,主要用于直接引用的方式(比如使用script 标签)
20+
libraryExport: "default", // 对外暴露default属性,就可以直接调用default里的属性
21+
globalObject: 'this', // 定义全局变量,兼容node和浏览器运行,避免出现"window is not defined"的情况
22+
libraryTarget: 'umd' // 定义打包方式Universal Module Definition,同时支持在CommonJS、AMD和全局变量使用
23+
},
24+
module: {
25+
rules: [
26+
{ test: /\.vue$/,
27+
use: 'vue-loader'
28+
},
29+
{
30+
test: /\.(png|svg|jpg|gif)$/,
31+
use: [
32+
'file-loader'
33+
]
34+
}
35+
],
36+
},
37+
devServer: {
38+
clientLogLevel: 'warning',
39+
hot: true,
40+
contentBase: 'dist',
41+
compress: true,
42+
host: HOST,
43+
port: PORT,
44+
open: true,
45+
overlay: { warnings: false, errors: true },
46+
publicPath: '/',
47+
contentBase: path.join(__dirname, 'dist'),
48+
quiet: true
49+
},
50+
plugins: [
51+
new VueLoaderPlugin(),
52+
new HtmlWebpackPlugin({
53+
template: './example/index.html',
54+
filename: 'index.html',
55+
inject: true
56+
}),
57+
]
58+
}

example/img/button.png

1.18 KB
Loading

example/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
</body>
11+
</html>

example/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Vue from 'vue';
2+
import App from './index.vue';
3+
import LuckDraw from '../src/index.js';
4+
5+
Vue.use(LuckDraw)
6+
7+
new Vue({
8+
render: h => h(App)
9+
}).$mount('#app');

example/index.vue

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<LuckyWheel
3+
ref="LuckyWheel"
4+
width="300px"
5+
height="300px"
6+
:prizes="prizes"
7+
:default-style="defaultStyle"
8+
:blocks="blocks"
9+
:buttons="buttons"
10+
@start="startCallBack"
11+
@end="endCallBack"
12+
/>
13+
</template>
14+
15+
<script>
16+
export default {
17+
data () {
18+
return {
19+
prizes: [],
20+
defaultStyle: {
21+
fontColor: '#d64737',
22+
fontSize: '14px'
23+
},
24+
blocks: [
25+
{ padding: '13px', background: '#d64737' }
26+
],
27+
buttons: [
28+
{ radius: '50px', background: '#d64737' },
29+
{ radius: '45px', background: '#fff' },
30+
{ radius: '41px', background: '#f6c66f', pointer: true },
31+
{
32+
radius: '35px', background: '#ffdea0',
33+
imgs: [{ src: require('./img/button.png'), width: '65%', top: '-50%' }]
34+
}
35+
],
36+
}
37+
},
38+
mounted () {
39+
this.getPrizesList()
40+
},
41+
methods: {
42+
getPrizesList () {
43+
const prizes = []
44+
let data = ['1元红包', '100元红包', '0.5元红包', '2元红包', '10元红包', '50元红包', '0.3元红包', '5元红包']
45+
data.forEach((item, index) => {
46+
prizes.push({
47+
title: item,
48+
background: index % 2 ? '#f9e3bb' : '#f8d384',
49+
fonts: [{ text: item, top: '10%' }],
50+
imgs:[],
51+
})
52+
})
53+
this.prizes = prizes
54+
},
55+
startCallBack () {
56+
this.$refs.LuckyWheel.play()
57+
setTimeout(() => {
58+
this.$refs.LuckyWheel.stop(Math.random() * 8 >> 0)
59+
}, 3000)
60+
},
61+
endCallBack (prize) {
62+
alert(`恭喜你获得${prize.title}`)
63+
},
64+
}
65+
}
66+
</script>

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./dist/vue-luck-draw.common.js')
1+
module.exports = require('./package/vue-luck-draw.js')

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,26 @@
2020
"vue3",
2121
"index.js"
2222
],
23+
"scripts": {
24+
"build": "cross-env NODE_ENV=production webpack --config=build/webpack.config.js",
25+
"start": "cross-env NODE_ENV=development webpack serve --config=build/webpack.config.js"
26+
},
2327
"homepage": "https://100px.net",
2428
"dependencies": {
25-
"lucky-canvas": "^1.5.3"
29+
"clean-webpack-plugin": "^3.0.0",
30+
"lucky-canvas": "^1.5.3",
31+
"vue": "^2.6.12"
32+
},
33+
"devDependencies": {
34+
"copy-webpack-plugin": "^8.0.0",
35+
"cross-env": "^7.0.3",
36+
"file-loader": "^6.2.0",
37+
"html-webpack-plugin": "^5.3.1",
38+
"mini-css-extract-plugin": "^1.3.9",
39+
"vue-loader": "^15.9.6",
40+
"vue-template-compiler": "^2.6.12",
41+
"webpack": "^5.27.1",
42+
"webpack-cli": "^4.5.0",
43+
"webpack-dev-server": "^3.11.2"
2644
}
2745
}

package/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Document</title><script defer="defer" src="vue-luck-draw.js"></script></head><body><div id="app"></div></body></html>

package/vue-luck-draw.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*! *****************************************************************************
2+
Copyright (c) Microsoft Corporation.
3+
4+
Permission to use, copy, modify, and/or distribute this software for any
5+
purpose with or without fee is hereby granted.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13+
PERFORMANCE OF THIS SOFTWARE.
14+
***************************************************************************** */

0 commit comments

Comments
 (0)