├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .postcssrc.js
├── README.md
├── build
├── build.js
├── check-versions.js
├── logo.png
├── utils.js
├── vue-loader.conf.js
├── webpack.base.conf.js
├── webpack.dev.conf.js
└── webpack.prod.conf.js
├── config
├── dev.env.js
├── index.js
├── prod.env.js
└── test.env.js
├── dist
└── vue-baberrage.js
├── docs
├── css
│ ├── app.2f5a7ad3.css
│ └── chunk-vendors.f055c36f.css
├── favicon.ico
├── img
│ └── logo.e113043f.png
├── index.html
├── js
│ ├── about.a807c8cf.js
│ ├── about.a807c8cf.js.map
│ ├── app.162a2c5e.js
│ ├── app.162a2c5e.js.map
│ ├── app.8763720e.js
│ ├── app.8763720e.js.map
│ ├── app.c72daff4.js
│ ├── app.c72daff4.js.map
│ ├── chunk-vendors.bbae5265.js
│ ├── chunk-vendors.bbae5265.js.map
│ ├── chunk-vendors.df1b52d7.js
│ ├── chunk-vendors.df1b52d7.js.map
│ ├── chunk-vendors.ff8a496d.js
│ └── chunk-vendors.ff8a496d.js.map
├── logo.png
└── zh
│ └── README.md
├── index.html
├── package-lock.json
├── package.json
├── rollup.config.js
├── screenshot
├── demo-show.gif
└── demo.gif
├── src
├── App.vue
├── assets
│ ├── avatar.jpg
│ └── logo.png
├── lib
│ ├── components
│ │ └── vue-baberrage-msg
│ │ │ └── index.vue
│ ├── constants
│ │ └── index.js
│ ├── index.js
│ ├── utils
│ │ └── widthCalcultor.js
│ └── vue-baberrage.vue
└── main.js
├── static
├── .gitkeep
└── avatar.jpg
├── test
└── unit
│ ├── .eslintrc
│ ├── jest.conf.js
│ ├── setup.js
│ └── specs
│ └── HelloWorld.spec.js
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env"
4 | ],
5 | "plugins": ["@babel/plugin-syntax-dynamic-import"]
6 | }
7 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 | /test/unit/coverage/
6 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | extends: [
12 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
13 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
14 | 'plugin:vue/essential',
15 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
16 | 'standard'
17 | ],
18 | // required to lint *.vue files
19 | plugins: [
20 | 'vue'
21 | ],
22 | // add your custom rules here
23 | rules: {
24 | // allow async-await
25 | 'generator-star-spacing': 'off',
26 | // allow debugger during development
27 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | npm-debug.log*
4 | yarn-debug.log*
5 | yarn-error.log*
6 | /test/unit/coverage/
7 | dist/
8 | dist/*
9 |
10 | # Editor directories and files
11 | .idea
12 | .vscode
13 | *.suo
14 | *.ntvs*
15 | *.njsproj
16 | *.sln
17 |
18 | .history
--------------------------------------------------------------------------------
/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Barrage plugin for Vue.js.
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | Overview •
19 | Overview •
20 | Demo •
21 | Installation •
22 | Usage •
23 | Plug Options •
24 | Roadmap
25 |
26 |
27 | ## Introduction
28 |
29 | Baberrage is one of the popular comment perform style in China.
30 |
31 | ## Overview
32 |
33 | 
34 |
35 | GIF performance is not good enough. Please refer to [DEMO](http://blog.chenhaotaishuaile.com/vue-baberrage/) page
36 |
37 | [中文文档](/docs/zh/README.md)
38 |
39 | ## Demo
40 |
41 | See the [DEMO](https://blog.chenhaotaishuaile.com/vue-baberrage/) page
42 |
43 | ## Installation
44 |
45 | 1) Install package via NPM
46 |
47 | ```bash
48 | npm i vue-baberrage
49 | ```
50 | 2) Install plugin within project
51 |
52 | ```javascript
53 | import Vue from 'vue'
54 | import { vueBaberrage } from 'vue-baberrage'
55 | Vue.use(vueBaberrage)
56 | ```
57 | or
58 |
59 | ```javascript
60 | const vueBaberrage = request('vue-baberrage').vueBaberrage
61 | ```
62 |
63 | or
64 |
65 | ```html
66 |
67 | ```
68 |
69 | ## Usage
70 |
71 | 1) Template
72 | `isShow` and `barrageList` are necessary.
73 |
74 | ```html
75 |
76 |
81 |
82 |
83 | ```
84 |
85 | 2) Script
86 |
87 | ```javascript
88 | import { MESSAGE_TYPE } from 'vue-baberrage'
89 |
90 | export default {
91 | name: 'app',
92 | data () {
93 | return {
94 | msg: 'Hello vue-baberrage',
95 | barrageIsShow: true,
96 | currentId : 0,
97 | barrageLoop: false,
98 | barrageList: []
99 | }
100 | },
101 | methods:{
102 | addToList (){
103 | this.barrageList.push({
104 | id: ++this.currentId,
105 | avatar: "./static/avatar.jpg",
106 | msg: this.msg,
107 | time: 5,
108 | type: MESSAGE_TYPE.NORMAL
109 | });
110 | ...
111 | ```
112 |
113 | 3) Already done
114 |
115 | Just two step, and add new barrage message by pushing data into the `barrageList`. You needn't concern about the management of the barrageList, it will be handled by vue-baberrage. Suggest the `barrageList` store into the Vuex.
116 |
117 | ## Custom Example
118 |
119 | New function in version 3.2.0. Support provides VNode to render the barrage.
120 | ````javascript
121 |
131 |
132 |
133 | {{slotProps.item.data.userName}}: {{slotProps.item.msg}}
134 |
135 |
136 |
137 | ````
138 | Customized your barrage UI as the slot of component.`props.item` data same as barrage data. Noticed that, if the width of barrage not fit in stage. You can add the field `extraWidth` in barrage data.
139 | ````javascript
140 | {
141 | id: ++this.currentId,
142 | avatar: "./static/avatar.jpg",
143 | msg: this.msg,
144 | data: {
145 | userName: 'more data'
146 | },
147 | time: 5,
148 | type: MESSAGE_TYPE.NORMAL,
149 | extraWidth: 60
150 | }
151 | ````
152 |
153 | Since vue-baberrage only count the width of length of the barrage's message.
154 |
155 | ## Plugin Options
156 |
157 | #### isShow
158 | - Default: `true`
159 | - Acceptable-Values: Boolean
160 | - Function: This is the switch that if barrage is displayed.
161 |
162 | #### barrageList
163 | - Default: `[]`
164 | - Acceptable-Values: Array
165 | - Function: The is the container for managing the all barrage messages.
166 |
167 | #### boxWidth
168 | - Default: `parent's Width`
169 | - Acceptable-Values: Number
170 | - Function: Determine the width of the stage.
171 |
172 | #### boxHeight
173 | - Default: `window's Height`
174 | - Acceptable-Values: Number
175 | - Function: Determine the height of the stage.
176 |
177 | #### messageHeight
178 | - Default: `message's Height`
179 | - Acceptable-Values: Number
180 | - Function: Determine the height of the message.
181 |
182 | #### maxWordCount
183 | - Default: 60
184 | - Acceptable-Values: Number
185 | - Function: Determine the word count of the message.
186 |
187 | #### loop
188 | - Default: `false`
189 | - Acceptable-Values: Boolean
190 | - Function: Loop or not.
191 |
192 | #### throttleGap
193 | - Default: 2000
194 | - Acceptable-Values: Number
195 | - Function: The gap time between the message
196 |
197 | #### posRender
198 | - Default: null
199 | - Acceptable-Values: Function
200 | - Function: To customize the lane of babbarrage messages.
201 | - Return: The function muse return the index of the lane.
202 |
203 | #### lanesCount
204 | - Default: 0
205 | - Acceptable-Values: Number
206 | - Function: To fixed the number of the lanes.
207 |
208 | ## Barrage Message Options
209 |
210 | #### id
211 | - Default: `null`
212 | - Acceptable-Values: Number
213 | - Function: For distinguish with other barrage messages.
214 |
215 | #### avatar
216 | - Default: `#`
217 | - Acceptable-Values: String
218 | - Function: Show the avatar of the barrage message.
219 |
220 | #### msg
221 | - Default: `null`
222 | - Acceptable-Values: String
223 | - Function: The content of the barrage message.
224 |
225 | #### barrageStyle
226 | - Default: `normal`
227 | - Acceptable-Values: String
228 | - Function: the css class name of the barrage message.
229 |
230 | #### time
231 | - Default: `10`
232 | - Acceptable-Values: Number
233 | - Function: How long does the barrage message show.(Seconds)
234 |
235 | #### type
236 | - Default: MESSAGE_TYPE.NORMAL
237 | - Acceptable-Values: Symbol
238 | - Function: The type of the barrage message.
239 | MESSAGE_TYPE.NORMAL for scroll from right to left.
240 | MESSAGE_TYPE.FROM_TOP for fixed on the top of the stage.
241 |
242 | #### extraWidth
243 | - Default: 0
244 | - Acceptable-Values: Number
245 | - Function: Add extra width to the barrage message.
246 |
247 | ## Events
248 |
249 | `barrage-list-empty` when the `barrageList` is empty will be called.
250 |
251 | ```html
252 |
258 | ```
259 |
260 | ## Roadmap
261 |
262 | #### Version 0.0.1
263 | - Realized the basic functionality.
264 |
265 | #### Version 1.0.0
266 | - Performance improvement.
267 |
268 | #### Version 1.2.0
269 | - Code specification
270 | - Performance improvement.
271 |
272 | #### Version 2.1.2
273 | - Used ES6.
274 | - Performance improvement.
275 |
276 | #### Version 2.1.9
277 | - Added Throttling
278 |
279 | #### Version 3.1.0
280 | - Used Rollup to build.
281 | - Add `posRender` attribute for customizing the show up lane of baberrage messages.
282 | - Fixed issues.
283 |
284 | #### Version 3.2.0
285 | - Support customize baberrage.
286 | - Fixed issues.
287 |
288 | ## Future
289 | I am developing `Vue-Baberrage-Plus`, difference between `Vue-Barrage` and `Vue-Baberrage-Plus` is former will be used for a tool, and `Plus` is a baberrage system.
290 |
--------------------------------------------------------------------------------
/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/superhos/vue-baberrage/333d3d10658a0c932b8fa1a7a9f266f2b53a9011/build/logo.png
--------------------------------------------------------------------------------
/build/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const config = require('../config')
4 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
5 | const packageConfig = require('../package.json')
6 |
7 | exports.assetsPath = function (_path) {
8 | const assetsSubDirectory = process.env.NODE_ENV === 'production'
9 | ? config.build.assetsSubDirectory
10 | : config.dev.assetsSubDirectory
11 |
12 | return path.posix.join(assetsSubDirectory, _path)
13 | }
14 |
15 | exports.cssLoaders = function (options) {
16 | options = options || {}
17 |
18 | const cssLoader = {
19 | loader: 'css-loader',
20 | options: {
21 | sourceMap: options.sourceMap
22 | }
23 | }
24 |
25 | const postcssLoader = {
26 | loader: 'postcss-loader',
27 | options: {
28 | sourceMap: options.sourceMap
29 | }
30 | }
31 |
32 | // generate loader string to be used with extract text plugin
33 | function generateLoaders (loader, loaderOptions) {
34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
35 |
36 | if (loader) {
37 | loaders.push({
38 | loader: loader + '-loader',
39 | options: Object.assign({}, loaderOptions, {
40 | sourceMap: options.sourceMap
41 | })
42 | })
43 | }
44 |
45 | // Extract CSS when that option is specified
46 | // (which is the case during production build)
47 | if (options.extract) {
48 | return ExtractTextPlugin.extract({
49 | use: loaders,
50 | fallback: 'vue-style-loader'
51 | })
52 | } else {
53 | return ['vue-style-loader'].concat(loaders)
54 | }
55 | }
56 |
57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
58 | return {
59 | css: generateLoaders(),
60 | postcss: generateLoaders(),
61 | less: generateLoaders('less'),
62 | stylus: generateLoaders('stylus'),
63 | styl: generateLoaders('stylus')
64 | }
65 | }
66 |
67 | // Generate loaders for standalone style files (outside of .vue)
68 | exports.styleLoaders = function (options) {
69 | const output = []
70 | const loaders = exports.cssLoaders(options)
71 |
72 | for (const extension in loaders) {
73 | const loader = loaders[extension]
74 | output.push({
75 | test: new RegExp('\\.' + extension + '$'),
76 | use: loader
77 | })
78 | }
79 |
80 | return output
81 | }
82 |
83 | exports.createNotifierCallback = () => {
84 | const notifier = require('node-notifier')
85 |
86 | return (severity, errors) => {
87 | if (severity !== 'error') return
88 |
89 | const error = errors[0]
90 | const filename = error.file && error.file.split('!').pop()
91 |
92 | notifier.notify({
93 | title: packageConfig.name,
94 | message: severity + ': ' + error.name,
95 | subtitle: filename || '',
96 | icon: path.join(__dirname, 'logo.png')
97 | })
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | const createLintingRule = () => ({
12 | test: /\.(js|vue)$/,
13 | loader: 'eslint-loader',
14 | enforce: 'pre',
15 | include: [resolve('src'), resolve('test')],
16 | options: {
17 | formatter: require('eslint-friendly-formatter'),
18 | emitWarning: !config.dev.showEslintErrorsInOverlay
19 | }
20 | })
21 |
22 | module.exports = {
23 | context: path.resolve(__dirname, '../'),
24 | entry: {
25 | app: './src/main.js'
26 | },
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: '[name].js',
30 | publicPath: process.env.NODE_ENV === 'production'
31 | ? config.build.assetsPublicPath
32 | : config.dev.assetsPublicPath
33 | },
34 | resolve: {
35 | extensions: ['.js', '.vue', '.json'],
36 | alias: {
37 | 'vue$': 'vue/dist/vue.esm.js',
38 | '@': resolve('src'),
39 | }
40 | },
41 | module: {
42 | rules: [
43 | ...(config.dev.useEslint ? [createLintingRule()] : []),
44 | {
45 | test: /\.vue$/,
46 | loader: 'vue-loader',
47 | options: vueLoaderConfig
48 | },
49 | {
50 | test: /\.js$/,
51 | loader: 'babel-loader',
52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53 | },
54 | {
55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
56 | loader: 'url-loader',
57 | options: {
58 | limit: 10000,
59 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
60 | }
61 | },
62 | {
63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
64 | loader: 'url-loader',
65 | options: {
66 | limit: 10000,
67 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
68 | }
69 | },
70 | {
71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72 | loader: 'url-loader',
73 | options: {
74 | limit: 10000,
75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76 | }
77 | }
78 | ]
79 | },
80 | node: {
81 | // prevent webpack from injecting useless setImmediate polyfill because Vue
82 | // source contains it (although only uses it if it's native).
83 | setImmediate: false,
84 | // prevent webpack from injecting mocks to Node native modules
85 | // that does not make sense for the client
86 | dgram: 'empty',
87 | fs: 'empty',
88 | net: 'empty',
89 | tls: 'empty',
90 | child_process: 'empty'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const webpack = require('webpack')
4 | const config = require('../config')
5 | const merge = require('webpack-merge')
6 | const path = require('path')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 | const CopyWebpackPlugin = require('copy-webpack-plugin')
9 | const HtmlWebpackPlugin = require('html-webpack-plugin')
10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
11 | const portfinder = require('portfinder')
12 |
13 | const HOST = process.env.HOST
14 | const PORT = process.env.PORT && Number(process.env.PORT)
15 |
16 | const devWebpackConfig = merge(baseWebpackConfig, {
17 | mode: 'development',
18 | module: {
19 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
20 | },
21 | // cheap-module-eval-source-map is faster for development
22 | devtool: config.dev.devtool,
23 |
24 | // these devServer options should be customized in /config/index.js
25 | devServer: {
26 | clientLogLevel: 'warning',
27 | historyApiFallback: {
28 | rewrites: [
29 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
30 | ],
31 | },
32 | hot: true,
33 | contentBase: false, // since we use CopyWebpackPlugin.
34 | compress: true,
35 | host: HOST || config.dev.host,
36 | port: PORT || config.dev.port,
37 | open: config.dev.autoOpenBrowser,
38 | overlay: config.dev.errorOverlay
39 | ? { warnings: false, errors: true }
40 | : false,
41 | publicPath: config.dev.assetsPublicPath,
42 | proxy: config.dev.proxyTable,
43 | quiet: true, // necessary for FriendlyErrorsPlugin
44 | watchOptions: {
45 | poll: config.dev.poll,
46 | }
47 | },
48 | plugins: [
49 | new webpack.DefinePlugin({
50 | 'process.env': require('../config/dev.env')
51 | }),
52 | new webpack.HotModuleReplacementPlugin(),
53 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
54 | new webpack.NoEmitOnErrorsPlugin(),
55 | // https://github.com/ampedandwired/html-webpack-plugin
56 | new HtmlWebpackPlugin({
57 | filename: 'index.html',
58 | template: 'index.html',
59 | inject: true
60 | }),
61 | // copy custom static assets
62 | new CopyWebpackPlugin([
63 | {
64 | from: path.resolve(__dirname, '../static'),
65 | to: config.dev.assetsSubDirectory,
66 | ignore: ['.*']
67 | }
68 | ])
69 | ]
70 | })
71 |
72 | module.exports = new Promise((resolve, reject) => {
73 | portfinder.basePort = process.env.PORT || config.dev.port
74 | portfinder.getPort((err, port) => {
75 | if (err) {
76 | reject(err)
77 | } else {
78 | // publish the new Port, necessary for e2e tests
79 | process.env.PORT = port
80 | // add port to devServer config
81 | devWebpackConfig.devServer.port = port
82 |
83 | // Add FriendlyErrorsPlugin
84 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
85 | compilationSuccessInfo: {
86 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
87 | },
88 | onErrors: config.dev.notifyOnErrors
89 | ? utils.createNotifierCallback()
90 | : undefined
91 | }))
92 |
93 | resolve(devWebpackConfig)
94 | }
95 | })
96 | })
97 |
--------------------------------------------------------------------------------
/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const webpack = require('webpack')
5 | const config = require('../config')
6 | const merge = require('webpack-merge')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 | const CopyWebpackPlugin = require('copy-webpack-plugin')
9 | const HtmlWebpackPlugin = require('html-webpack-plugin')
10 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
13 |
14 | const env = process.env.NODE_ENV === 'testing'
15 | ? require('../config/test.env')
16 | : require('../config/prod.env')
17 |
18 | const webpackConfig = merge(baseWebpackConfig, {
19 | mode: 'production',
20 | module: {
21 | rules: utils.styleLoaders({
22 | sourceMap: config.build.productionSourceMap,
23 | extract: true,
24 | usePostCSS: true
25 | })
26 | },
27 | devtool: config.build.productionSourceMap ? config.build.devtool : false,
28 | output: {
29 | path: config.build.assetsRoot,
30 | filename: utils.assetsPath('js/[name].[chunkhash].js'),
31 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
32 | },
33 | plugins: [
34 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
35 | new webpack.DefinePlugin({
36 | 'process.env': env
37 | }),
38 | new UglifyJsPlugin({
39 | uglifyOptions: {
40 | compress: {
41 | warnings: false
42 | }
43 | },
44 | sourceMap: config.build.productionSourceMap,
45 | parallel: true
46 | }),
47 | // extract css into its own file
48 | new ExtractTextPlugin({
49 | filename: utils.assetsPath('css/[name].[contenthash].css'),
50 | // Setting the following option to `false` will not extract CSS from codesplit chunks.
51 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
52 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
53 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
54 | allChunks: true,
55 | }),
56 | // Compress extracted CSS. We are using this plugin so that possible
57 | // duplicated CSS from different components can be deduped.
58 | new OptimizeCSSPlugin({
59 | cssProcessorOptions: config.build.productionSourceMap
60 | ? { safe: true, map: { inline: false } }
61 | : { safe: true }
62 | }),
63 | // generate dist index.html with correct asset hash for caching.
64 | // you can customize output by editing /index.html
65 | // see https://github.com/ampedandwired/html-webpack-plugin
66 | new HtmlWebpackPlugin({
67 | filename: process.env.NODE_ENV === 'testing'
68 | ? 'index.html'
69 | : config.build.index,
70 | template: 'index.html',
71 | inject: true,
72 | minify: {
73 | removeComments: true,
74 | collapseWhitespace: true,
75 | removeAttributeQuotes: true
76 | // more options:
77 | // https://github.com/kangax/html-minifier#options-quick-reference
78 | },
79 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin
80 | chunksSortMode: 'dependency'
81 | }),
82 | // keep module.id stable when vendor modules does not change
83 | new webpack.HashedModuleIdsPlugin(),
84 | // enable scope hoisting
85 | new webpack.optimize.ModuleConcatenationPlugin(),
86 | // split vendor js into its own file
87 | new webpack.optimize.CommonsChunkPlugin({
88 | name: 'vendor',
89 | minChunks (module) {
90 | // any required modules inside node_modules are extracted to vendor
91 | return (
92 | module.resource &&
93 | /\.js$/.test(module.resource) &&
94 | module.resource.indexOf(
95 | path.join(__dirname, '../node_modules')
96 | ) === 0
97 | )
98 | }
99 | }),
100 | // extract webpack runtime and module manifest to its own file in order to
101 | // prevent vendor hash from being updated whenever app bundle is updated
102 | new webpack.optimize.CommonsChunkPlugin({
103 | name: 'manifest',
104 | minChunks: Infinity
105 | }),
106 | // This instance extracts shared chunks from code splitted chunks and bundles them
107 | // in a separate chunk, similar to the vendor chunk
108 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
109 | new webpack.optimize.CommonsChunkPlugin({
110 | name: 'app',
111 | async: 'vendor-async',
112 | children: true,
113 | minChunks: 3
114 | }),
115 |
116 | // copy custom static assets
117 | new CopyWebpackPlugin([
118 | {
119 | from: path.resolve(__dirname, '../static'),
120 | to: config.build.assetsSubDirectory,
121 | ignore: ['.*']
122 | }
123 | ])
124 | ]
125 | })
126 |
127 | if (config.build.productionGzip) {
128 | const CompressionWebpackPlugin = require('compression-webpack-plugin')
129 |
130 | webpackConfig.plugins.push(
131 | new CompressionWebpackPlugin({
132 | asset: '[path].gz[query]',
133 | algorithm: 'gzip',
134 | test: new RegExp(
135 | '\\.(' +
136 | config.build.productionGzipExtensions.join('|') +
137 | ')$'
138 | ),
139 | threshold: 10240,
140 | minRatio: 0.8
141 | })
142 | )
143 | }
144 |
145 | if (config.build.bundleAnalyzerReport) {
146 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
147 | webpackConfig.plugins.push(new BundleAnalyzerPlugin())
148 | }
149 |
150 | module.exports = webpackConfig
151 |
--------------------------------------------------------------------------------
/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 |
10 | // Paths
11 | assetsSubDirectory: 'static',
12 | assetsPublicPath: '/',
13 | proxyTable: {},
14 |
15 | // Various Dev Server settings
16 | host: 'localhost', // can be overwritten by process.env.HOST
17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
18 | autoOpenBrowser: false,
19 | errorOverlay: true,
20 | notifyOnErrors: true,
21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
22 |
23 | // Use Eslint Loader?
24 | // If true, your code will be linted during bundling and
25 | // linting errors and warnings will be shown in the console.
26 | useEslint: true,
27 | // If true, eslint errors and warnings will also be shown in the error overlay
28 | // in the browser.
29 | showEslintErrorsInOverlay: false,
30 |
31 | /**
32 | * Source Maps
33 | */
34 |
35 | // https://webpack.js.org/configuration/devtool/#development
36 | devtool: 'cheap-module-eval-source-map',
37 |
38 | // If you have problems debugging vue-files in devtools,
39 | // set this to false - it *may* help
40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
41 | cacheBusting: true,
42 |
43 | cssSourceMap: true
44 | },
45 |
46 | build: {
47 | // Template for index.html
48 | index: path.resolve(__dirname, '../dist/index.html'),
49 |
50 | // Paths
51 | assetsRoot: path.resolve(__dirname, '../dist'),
52 | assetsSubDirectory: 'static',
53 | assetsPublicPath: '/',
54 |
55 | /**
56 | * Source Maps
57 | */
58 |
59 | productionSourceMap: true,
60 | // https://webpack.js.org/configuration/devtool/#production
61 | devtool: '#source-map',
62 |
63 | // Gzip off by default as many popular static hosts such as
64 | // Surge or Netlify already gzip all static assets for you.
65 | // Before setting to `true`, make sure to:
66 | // npm install --save-dev compression-webpack-plugin
67 | productionGzip: false,
68 | productionGzipExtensions: ['js', 'css'],
69 |
70 | // Run the build command with an extra argument to
71 | // View the bundle analyzer report after build finishes:
72 | // `npm run build --report`
73 | // Set to `true` or `false` to always turn it on or off
74 | bundleAnalyzerReport: process.env.npm_config_report
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/config/test.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const devEnv = require('./dev.env')
4 |
5 | module.exports = merge(devEnv, {
6 | NODE_ENV: '"testing"'
7 | })
8 |
--------------------------------------------------------------------------------
/dist/vue-baberrage.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("timers")):"function"==typeof define&&define.amd?define(["exports","timers"],t):t((e=e||self)["vue-baberrage"]={},e.timers)}(this,(function(e,t){"use strict";function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function a(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t>>((3&t)<<3)&255;return i}}})),s=[],o=0;o<256;++o)s[o]=(o+256).toString(16).substr(1);var u=function(e,t){var n=t||0,i=s;return[i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],"-",i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]],i[e[n++]]].join("")};var l=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var a=(e=e||{}).random||(e.rng||r)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t)for(var s=0;s<16;++s)t[i+s]=a[s];return t||u(a)},d=/[A-Z]/g,h=/^ms-/,m={};function p(e){return"-"+e.toLowerCase()}function c(e){if(m.hasOwnProperty(e))return m[e];var t=e.replace(d,p);return m[e]=h.test(t)?"-"+t:t}var f={name:"vue-baberrage-message",props:{item:{type:Object,default:function(){return{}}}},data:function(){return{isCustom:!1}},mounted:function(){this.isCustom=!!this.$scopedSlots.default}};function b(e,t,n,i,a,r,s,o,u,l){"boolean"!=typeof s&&(u=o,o=s,s=!1);const d="function"==typeof n?n.options:n;let h;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,a&&(d.functional=!0)),i&&(d._scopeId=i),r?(h=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,u(e)),e&&e._registeredComponents&&e._registeredComponents.add(r)},d._ssrRegister=h):t&&(h=s?function(e){t.call(this,l(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,o(e))}),h)if(d.functional){const e=d.render;d.render=function(t,n){return h.call(n),e(t,n)}}else{const e=d.beforeCreate;d.beforeCreate=e?[].concat(e,h):[h]}return n}const g="undefined"!=typeof navigator&&/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());function A(e){return(e,t)=>function(e,t){const n=g?t.media||"default":e,i=y[n]||(y[n]={ids:new Set,styles:[]});if(!i.ids.has(e)){i.ids.add(e);let n=t.source;if(t.map&&(n+="\n/*# sourceURL="+t.map.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(t.map))))+" */"),i.element||(i.element=document.createElement("style"),i.element.type="text/css",t.media&&i.element.setAttribute("media",t.media),void 0===v&&(v=document.head||document.getElementsByTagName("head")[0]),v.appendChild(i.element)),"styleSheet"in i.element)i.styles.push(n),i.element.styleSheet.cssText=i.styles.filter(Boolean).join("\n");else{const e=i.ids.size-1,t=document.createTextNode(n),a=i.element.childNodes;a[e]&&i.element.removeChild(a[e]),a.length?i.element.insertBefore(t,a[e]):i.element.appendChild(t)}}}(e,t)}let v;const y={};const x=f;var w=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"baberrage-item",class:e.item.barrageStyle,style:e.item.style},[e.isCustom?[e._t("default")]:n("div",{staticClass:"normal"},[n("div",{staticClass:"baberrage-avatar"},[n("img",{attrs:{src:e.item.avatar}})]),e._v(" "),n("div",{staticClass:"baberrage-msg"},[e._v(e._s(e.item.msg))])])],2)};w._withStripped=!0;const C=b({render:w,staticRenderFns:[]},(function(e){e&&e("data-v-600778c7_0",{source:".baberrage-item {\n position: absolute;\n width: auto;\n display: block;\n color: #000;\n transform: translateX(500%);\n padding: 5px 0 5px 0;\n box-sizing: border-box;\n text-align: left;\n white-space: nowrap;\n}\n.baberrage-item .normal {\n display: flex;\n box-sizing: border-box;\n padding: 5px;\n}\n.baberrage-item .normal .baberrage-avatar {\n width: 30px;\n height: 30px;\n border-radius: 50px;\n overflow: hidden;\n}\n.baberrage-item .normal .baberrage-avatar img {\n width: 30px;\n}\n.baberrage-item .baberrage-msg {\n line-height: 30px;\n padding-left: 8px;\n white-space: nowrap;\n}\n.baberrage-item .normal {\n background: rgba(0, 0, 0, 0.7);\n border-radius: 100px;\n color: #FFF;\n}\n",map:{version:3,sources:["index.vue","/Users/chenhao/Documents/work/vue-baberrage/src/lib/components/vue-baberrage-msg/index.vue"],names:[],mappings:"AAAA;EACE,kBAAkB;EAClB,WAAW;EACX,cAAc;EACd,WAAW;EACX,2BAA2B;EAC3B,oBAAoB;EACpB,sBAAsB;EACtB,gBAAgB;EAChB,mBAAmB;AACrB;AACA;EACE,aAAa;EACb,sBAAsB;EACtB,YAAY;AACd;AACA;EACE,WAAW;EACX,YAAY;EACZ,mBAAmB;EACnB,gBAAgB;AAClB;AACA;EACE,WAAW;AACb;AACA;EACE,iBAAiB;EACjB,iBAAiB;EACjB,mBAAmB;AACrB;AACA;EACE,8BAA8B;ECChC,oBAAA;EACA,WAAA;AACA",file:"index.vue",sourcesContent:[".baberrage-item {\n position: absolute;\n width: auto;\n display: block;\n color: #000;\n transform: translateX(500%);\n padding: 5px 0 5px 0;\n box-sizing: border-box;\n text-align: left;\n white-space: nowrap;\n}\n.baberrage-item .normal {\n display: flex;\n box-sizing: border-box;\n padding: 5px;\n}\n.baberrage-item .normal .baberrage-avatar {\n width: 30px;\n height: 30px;\n border-radius: 50px;\n overflow: hidden;\n}\n.baberrage-item .normal .baberrage-avatar img {\n width: 30px;\n}\n.baberrage-item .baberrage-msg {\n line-height: 30px;\n padding-left: 8px;\n white-space: nowrap;\n}\n.baberrage-item .normal {\n background: rgba(0, 0, 0, 0.7);\n border-radius: 100px;\n color: #FFF;\n}\n",'\n \n\n