正在显示
45 个修改的文件
包含
1720 行增加
和
0 行删除
.babelrc
0 → 100644
| 1 | +{ | ||
| 2 | + "comments": false, | ||
| 3 | + "env": { | ||
| 4 | + "test": { | ||
| 5 | + "presets": [ | ||
| 6 | + ["env", { | ||
| 7 | + "targets": { "node": 7 } | ||
| 8 | + }], | ||
| 9 | + "stage-0" | ||
| 10 | + ], | ||
| 11 | + "plugins": ["istanbul"] | ||
| 12 | + }, | ||
| 13 | + "main": { | ||
| 14 | + "presets": [ | ||
| 15 | + ["env", { | ||
| 16 | + "targets": { "node": 7 } | ||
| 17 | + }], | ||
| 18 | + "stage-0" | ||
| 19 | + ] | ||
| 20 | + }, | ||
| 21 | + "renderer": { | ||
| 22 | + "presets": [ | ||
| 23 | + ["env", { | ||
| 24 | + "modules": false | ||
| 25 | + }], | ||
| 26 | + "stage-0" | ||
| 27 | + ] | ||
| 28 | + }, | ||
| 29 | + "web": { | ||
| 30 | + "presets": [ | ||
| 31 | + ["env", { | ||
| 32 | + "modules": false | ||
| 33 | + }], | ||
| 34 | + "stage-0" | ||
| 35 | + ] | ||
| 36 | + } | ||
| 37 | + }, | ||
| 38 | + "plugins": ["transform-runtime"] | ||
| 39 | +} |
.electron-vue/build.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +process.env.NODE_ENV = 'production' | ||
| 4 | + | ||
| 5 | +const { say } = require('cfonts') | ||
| 6 | +const chalk = require('chalk') | ||
| 7 | +const del = require('del') | ||
| 8 | +const { spawn } = require('child_process') | ||
| 9 | +const webpack = require('webpack') | ||
| 10 | +const Multispinner = require('multispinner') | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +const mainConfig = require('./webpack.main.config') | ||
| 14 | +const rendererConfig = require('./webpack.renderer.config') | ||
| 15 | +const webConfig = require('./webpack.web.config') | ||
| 16 | + | ||
| 17 | +const doneLog = chalk.bgGreen.white(' DONE ') + ' ' | ||
| 18 | +const errorLog = chalk.bgRed.white(' ERROR ') + ' ' | ||
| 19 | +const okayLog = chalk.bgBlue.white(' OKAY ') + ' ' | ||
| 20 | +const isCI = process.env.CI || false | ||
| 21 | + | ||
| 22 | +if (process.env.BUILD_TARGET === 'clean') clean() | ||
| 23 | +else if (process.env.BUILD_TARGET === 'web') web() | ||
| 24 | +else build() | ||
| 25 | + | ||
| 26 | +function clean () { | ||
| 27 | + del.sync(['build/*', '!build/icons', '!build/icons/icon.*']) | ||
| 28 | + console.log(`\n${doneLog}\n`) | ||
| 29 | + process.exit() | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +function build () { | ||
| 33 | + greeting() | ||
| 34 | + | ||
| 35 | + del.sync(['dist/electron/*', '!.gitkeep']) | ||
| 36 | + | ||
| 37 | + const tasks = ['main', 'renderer'] | ||
| 38 | + const m = new Multispinner(tasks, { | ||
| 39 | + preText: 'building', | ||
| 40 | + postText: 'process' | ||
| 41 | + }) | ||
| 42 | + | ||
| 43 | + let results = '' | ||
| 44 | + | ||
| 45 | + m.on('success', () => { | ||
| 46 | + process.stdout.write('\x1B[2J\x1B[0f') | ||
| 47 | + console.log(`\n\n${results}`) | ||
| 48 | + console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`) | ||
| 49 | + process.exit() | ||
| 50 | + }) | ||
| 51 | + | ||
| 52 | + pack(mainConfig).then(result => { | ||
| 53 | + results += result + '\n\n' | ||
| 54 | + m.success('main') | ||
| 55 | + }).catch(err => { | ||
| 56 | + m.error('main') | ||
| 57 | + console.log(`\n ${errorLog}failed to build main process`) | ||
| 58 | + console.error(`\n${err}\n`) | ||
| 59 | + process.exit(1) | ||
| 60 | + }) | ||
| 61 | + | ||
| 62 | + pack(rendererConfig).then(result => { | ||
| 63 | + results += result + '\n\n' | ||
| 64 | + m.success('renderer') | ||
| 65 | + }).catch(err => { | ||
| 66 | + m.error('renderer') | ||
| 67 | + console.log(`\n ${errorLog}failed to build renderer process`) | ||
| 68 | + console.error(`\n${err}\n`) | ||
| 69 | + process.exit(1) | ||
| 70 | + }) | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +function pack (config) { | ||
| 74 | + return new Promise((resolve, reject) => { | ||
| 75 | + config.mode = 'production' | ||
| 76 | + webpack(config, (err, stats) => { | ||
| 77 | + if (err) reject(err.stack || err) | ||
| 78 | + else if (stats.hasErrors()) { | ||
| 79 | + let err = '' | ||
| 80 | + | ||
| 81 | + stats.toString({ | ||
| 82 | + chunks: false, | ||
| 83 | + colors: true | ||
| 84 | + }) | ||
| 85 | + .split(/\r?\n/) | ||
| 86 | + .forEach(line => { | ||
| 87 | + err += ` ${line}\n` | ||
| 88 | + }) | ||
| 89 | + | ||
| 90 | + reject(err) | ||
| 91 | + } else { | ||
| 92 | + resolve(stats.toString({ | ||
| 93 | + chunks: false, | ||
| 94 | + colors: true | ||
| 95 | + })) | ||
| 96 | + } | ||
| 97 | + }) | ||
| 98 | + }) | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +function web () { | ||
| 102 | + del.sync(['dist/web/*', '!.gitkeep']) | ||
| 103 | + webConfig.mode = 'production' | ||
| 104 | + webpack(webConfig, (err, stats) => { | ||
| 105 | + if (err || stats.hasErrors()) console.log(err) | ||
| 106 | + | ||
| 107 | + console.log(stats.toString({ | ||
| 108 | + chunks: false, | ||
| 109 | + colors: true | ||
| 110 | + })) | ||
| 111 | + | ||
| 112 | + process.exit() | ||
| 113 | + }) | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +function greeting () { | ||
| 117 | + const cols = process.stdout.columns | ||
| 118 | + let text = '' | ||
| 119 | + | ||
| 120 | + if (cols > 85) text = 'lets-build' | ||
| 121 | + else if (cols > 60) text = 'lets-|build' | ||
| 122 | + else text = false | ||
| 123 | + | ||
| 124 | + if (text && !isCI) { | ||
| 125 | + say(text, { | ||
| 126 | + colors: ['yellow'], | ||
| 127 | + font: 'simple3d', | ||
| 128 | + space: false | ||
| 129 | + }) | ||
| 130 | + } else console.log(chalk.yellow.bold('\n lets-build')) | ||
| 131 | + console.log() | ||
| 132 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
.electron-vue/dev-client.js
0 → 100644
| 1 | +const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') | ||
| 2 | + | ||
| 3 | +hotClient.subscribe(event => { | ||
| 4 | + /** | ||
| 5 | + * Reload browser when HTMLWebpackPlugin emits a new index.html | ||
| 6 | + * | ||
| 7 | + * Currently disabled until jantimon/html-webpack-plugin#680 is resolved. | ||
| 8 | + * https://github.com/SimulatedGREG/electron-vue/issues/437 | ||
| 9 | + * https://github.com/jantimon/html-webpack-plugin/issues/680 | ||
| 10 | + */ | ||
| 11 | + // if (event.action === 'reload') { | ||
| 12 | + // window.location.reload() | ||
| 13 | + // } | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * Notify `mainWindow` when `main` process is compiling, | ||
| 17 | + * giving notice for an expected reload of the `electron` process | ||
| 18 | + */ | ||
| 19 | + if (event.action === 'compiling') { | ||
| 20 | + document.body.innerHTML += ` | ||
| 21 | + <style> | ||
| 22 | + #dev-client { | ||
| 23 | + background: #4fc08d; | ||
| 24 | + border-radius: 4px; | ||
| 25 | + bottom: 20px; | ||
| 26 | + box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3); | ||
| 27 | + color: #fff; | ||
| 28 | + font-family: 'Source Sans Pro', sans-serif; | ||
| 29 | + left: 20px; | ||
| 30 | + padding: 8px 12px; | ||
| 31 | + position: absolute; | ||
| 32 | + } | ||
| 33 | + </style> | ||
| 34 | + | ||
| 35 | + <div id="dev-client"> | ||
| 36 | + Compiling Main Process... | ||
| 37 | + </div> | ||
| 38 | + ` | ||
| 39 | + } | ||
| 40 | +}) |
.electron-vue/dev-runner.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +const chalk = require('chalk') | ||
| 4 | +const electron = require('electron') | ||
| 5 | +const path = require('path') | ||
| 6 | +const { say } = require('cfonts') | ||
| 7 | +const { spawn } = require('child_process') | ||
| 8 | +const webpack = require('webpack') | ||
| 9 | +const WebpackDevServer = require('webpack-dev-server') | ||
| 10 | +const webpackHotMiddleware = require('webpack-hot-middleware') | ||
| 11 | + | ||
| 12 | +const mainConfig = require('./webpack.main.config') | ||
| 13 | +const rendererConfig = require('./webpack.renderer.config') | ||
| 14 | + | ||
| 15 | +let electronProcess = null | ||
| 16 | +let manualRestart = false | ||
| 17 | +let hotMiddleware | ||
| 18 | + | ||
| 19 | +function logStats (proc, data) { | ||
| 20 | + let log = '' | ||
| 21 | + | ||
| 22 | + log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`) | ||
| 23 | + log += '\n\n' | ||
| 24 | + | ||
| 25 | + if (typeof data === 'object') { | ||
| 26 | + data.toString({ | ||
| 27 | + colors: true, | ||
| 28 | + chunks: false | ||
| 29 | + }).split(/\r?\n/).forEach(line => { | ||
| 30 | + log += ' ' + line + '\n' | ||
| 31 | + }) | ||
| 32 | + } else { | ||
| 33 | + log += ` ${data}\n` | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + log += '\n' + chalk.yellow.bold(`┗ ${new Array(28 + 1).join('-')}`) + '\n' | ||
| 37 | + | ||
| 38 | + console.log(log) | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +function startRenderer () { | ||
| 42 | + return new Promise((resolve, reject) => { | ||
| 43 | + rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer) | ||
| 44 | + rendererConfig.mode = 'development' | ||
| 45 | + const compiler = webpack(rendererConfig) | ||
| 46 | + hotMiddleware = webpackHotMiddleware(compiler, { | ||
| 47 | + log: false, | ||
| 48 | + heartbeat: 2500 | ||
| 49 | + }) | ||
| 50 | + | ||
| 51 | + compiler.hooks.compilation.tap('compilation', compilation => { | ||
| 52 | + compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => { | ||
| 53 | + hotMiddleware.publish({ action: 'reload' }) | ||
| 54 | + cb() | ||
| 55 | + }) | ||
| 56 | + }) | ||
| 57 | + | ||
| 58 | + compiler.hooks.done.tap('done', stats => { | ||
| 59 | + logStats('Renderer', stats) | ||
| 60 | + }) | ||
| 61 | + | ||
| 62 | + const server = new WebpackDevServer( | ||
| 63 | + compiler, | ||
| 64 | + { | ||
| 65 | + contentBase: path.join(__dirname, '../'), | ||
| 66 | + quiet: true, | ||
| 67 | + before (app, ctx) { | ||
| 68 | + app.use(hotMiddleware) | ||
| 69 | + ctx.middleware.waitUntilValid(() => { | ||
| 70 | + resolve() | ||
| 71 | + }) | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + ) | ||
| 75 | + | ||
| 76 | + server.listen(9080) | ||
| 77 | + }) | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +function startMain () { | ||
| 81 | + return new Promise((resolve, reject) => { | ||
| 82 | + mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main) | ||
| 83 | + mainConfig.mode = 'development' | ||
| 84 | + const compiler = webpack(mainConfig) | ||
| 85 | + | ||
| 86 | + compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => { | ||
| 87 | + logStats('Main', chalk.white.bold('compiling...')) | ||
| 88 | + hotMiddleware.publish({ action: 'compiling' }) | ||
| 89 | + done() | ||
| 90 | + }) | ||
| 91 | + | ||
| 92 | + compiler.watch({}, (err, stats) => { | ||
| 93 | + if (err) { | ||
| 94 | + console.log(err) | ||
| 95 | + return | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + logStats('Main', stats) | ||
| 99 | + | ||
| 100 | + if (electronProcess && electronProcess.kill) { | ||
| 101 | + manualRestart = true | ||
| 102 | + process.kill(electronProcess.pid) | ||
| 103 | + electronProcess = null | ||
| 104 | + startElectron() | ||
| 105 | + | ||
| 106 | + setTimeout(() => { | ||
| 107 | + manualRestart = false | ||
| 108 | + }, 5000) | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + resolve() | ||
| 112 | + }) | ||
| 113 | + }) | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +function startElectron () { | ||
| 117 | + var args = [ | ||
| 118 | + '--inspect=5858', | ||
| 119 | + path.join(__dirname, '../dist/electron/main.js') | ||
| 120 | + ] | ||
| 121 | + | ||
| 122 | + // detect yarn or npm and process commandline args accordingly | ||
| 123 | + if (process.env.npm_execpath.endsWith('yarn.js')) { | ||
| 124 | + args = args.concat(process.argv.slice(3)) | ||
| 125 | + } else if (process.env.npm_execpath.endsWith('npm-cli.js')) { | ||
| 126 | + args = args.concat(process.argv.slice(2)) | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + electronProcess = spawn(electron, args) | ||
| 130 | + | ||
| 131 | + electronProcess.stdout.on('data', data => { | ||
| 132 | + electronLog(data, 'blue') | ||
| 133 | + }) | ||
| 134 | + electronProcess.stderr.on('data', data => { | ||
| 135 | + electronLog(data, 'red') | ||
| 136 | + }) | ||
| 137 | + | ||
| 138 | + electronProcess.on('close', () => { | ||
| 139 | + if (!manualRestart) process.exit() | ||
| 140 | + }) | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +function electronLog (data, color) { | ||
| 144 | + let log = '' | ||
| 145 | + data = data.toString().split(/\r?\n/) | ||
| 146 | + data.forEach(line => { | ||
| 147 | + log += ` ${line}\n` | ||
| 148 | + }) | ||
| 149 | + if (/[0-9A-z]+/.test(log)) { | ||
| 150 | + console.log( | ||
| 151 | + chalk[color].bold('┏ Electron -------------------') + | ||
| 152 | + '\n\n' + | ||
| 153 | + log + | ||
| 154 | + chalk[color].bold('┗ ----------------------------') + | ||
| 155 | + '\n' | ||
| 156 | + ) | ||
| 157 | + } | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +function greeting () { | ||
| 161 | + const cols = process.stdout.columns | ||
| 162 | + let text = '' | ||
| 163 | + | ||
| 164 | + if (cols > 104) text = 'electron-vue' | ||
| 165 | + else if (cols > 76) text = 'electron-|vue' | ||
| 166 | + else text = false | ||
| 167 | + | ||
| 168 | + if (text) { | ||
| 169 | + say(text, { | ||
| 170 | + colors: ['yellow'], | ||
| 171 | + font: 'simple3d', | ||
| 172 | + space: false | ||
| 173 | + }) | ||
| 174 | + } else console.log(chalk.yellow.bold('\n electron-vue')) | ||
| 175 | + console.log(chalk.blue(' getting ready...') + '\n') | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +function init () { | ||
| 179 | + greeting() | ||
| 180 | + | ||
| 181 | + Promise.all([startRenderer(), startMain()]) | ||
| 182 | + .then(() => { | ||
| 183 | + startElectron() | ||
| 184 | + }) | ||
| 185 | + .catch(err => { | ||
| 186 | + console.error(err) | ||
| 187 | + }) | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +init() |
.electron-vue/webpack.main.config.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +process.env.BABEL_ENV = 'main' | ||
| 4 | + | ||
| 5 | +const path = require('path') | ||
| 6 | +const { dependencies } = require('../package.json') | ||
| 7 | +const webpack = require('webpack') | ||
| 8 | + | ||
| 9 | +const BabiliWebpackPlugin = require('babili-webpack-plugin') | ||
| 10 | + | ||
| 11 | +let mainConfig = { | ||
| 12 | + entry: { | ||
| 13 | + main: path.join(__dirname, '../src/main/index.js') | ||
| 14 | + }, | ||
| 15 | + externals: [ | ||
| 16 | + ...Object.keys(dependencies || {}) | ||
| 17 | + ], | ||
| 18 | + module: { | ||
| 19 | + rules: [ | ||
| 20 | + { | ||
| 21 | + test: /\.(js)$/, | ||
| 22 | + enforce: 'pre', | ||
| 23 | + exclude: /node_modules/, | ||
| 24 | + use: { | ||
| 25 | + loader: 'eslint-loader', | ||
| 26 | + options: { | ||
| 27 | + formatter: require('eslint-friendly-formatter') | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + }, | ||
| 31 | + { | ||
| 32 | + test: /\.js$/, | ||
| 33 | + use: 'babel-loader', | ||
| 34 | + exclude: /node_modules/ | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + test: /\.node$/, | ||
| 38 | + use: 'node-loader' | ||
| 39 | + } | ||
| 40 | + ] | ||
| 41 | + }, | ||
| 42 | + node: { | ||
| 43 | + __dirname: process.env.NODE_ENV !== 'production', | ||
| 44 | + __filename: process.env.NODE_ENV !== 'production' | ||
| 45 | + }, | ||
| 46 | + output: { | ||
| 47 | + filename: '[name].js', | ||
| 48 | + libraryTarget: 'commonjs2', | ||
| 49 | + path: path.join(__dirname, '../dist/electron') | ||
| 50 | + }, | ||
| 51 | + plugins: [ | ||
| 52 | + new webpack.NoEmitOnErrorsPlugin() | ||
| 53 | + ], | ||
| 54 | + resolve: { | ||
| 55 | + extensions: ['.js', '.json', '.node'] | ||
| 56 | + }, | ||
| 57 | + target: 'electron-main' | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +/** | ||
| 61 | + * Adjust mainConfig for development settings | ||
| 62 | + */ | ||
| 63 | +if (process.env.NODE_ENV !== 'production') { | ||
| 64 | + mainConfig.plugins.push( | ||
| 65 | + new webpack.DefinePlugin({ | ||
| 66 | + '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"` | ||
| 67 | + }) | ||
| 68 | + ) | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +/** | ||
| 72 | + * Adjust mainConfig for production settings | ||
| 73 | + */ | ||
| 74 | +if (process.env.NODE_ENV === 'production') { | ||
| 75 | + mainConfig.plugins.push( | ||
| 76 | + new BabiliWebpackPlugin(), | ||
| 77 | + new webpack.DefinePlugin({ | ||
| 78 | + 'process.env.NODE_ENV': '"production"' | ||
| 79 | + }) | ||
| 80 | + ) | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +module.exports = mainConfig |
.electron-vue/webpack.renderer.config.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +process.env.BABEL_ENV = 'renderer' | ||
| 4 | + | ||
| 5 | +const path = require('path') | ||
| 6 | +const { dependencies } = require('../package.json') | ||
| 7 | +const webpack = require('webpack') | ||
| 8 | + | ||
| 9 | +const BabiliWebpackPlugin = require('babili-webpack-plugin') | ||
| 10 | +const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
| 11 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin') | ||
| 12 | +const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
| 13 | +const { VueLoaderPlugin } = require('vue-loader') | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * List of node_modules to include in webpack bundle | ||
| 17 | + * | ||
| 18 | + * Required for specific packages like Vue UI libraries | ||
| 19 | + * that provide pure *.vue files that need compiling | ||
| 20 | + * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals | ||
| 21 | + */ | ||
| 22 | +let whiteListedModules = ['vue'] | ||
| 23 | + | ||
| 24 | +let rendererConfig = { | ||
| 25 | + devtool: '#cheap-module-eval-source-map', | ||
| 26 | + entry: { | ||
| 27 | + renderer: path.join(__dirname, '../src/renderer/main.js') | ||
| 28 | + }, | ||
| 29 | + externals: [ | ||
| 30 | + ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d)) | ||
| 31 | + ], | ||
| 32 | + module: { | ||
| 33 | + rules: [ | ||
| 34 | + { | ||
| 35 | + test: /\.(js|vue)$/, | ||
| 36 | + enforce: 'pre', | ||
| 37 | + exclude: /node_modules/, | ||
| 38 | + use: { | ||
| 39 | + loader: 'eslint-loader', | ||
| 40 | + options: { | ||
| 41 | + formatter: require('eslint-friendly-formatter') | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + }, | ||
| 45 | + { | ||
| 46 | + test: /\.scss$/, | ||
| 47 | + use: ['vue-style-loader', 'css-loader', 'sass-loader'] | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + test: /\.sass$/, | ||
| 51 | + use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax'] | ||
| 52 | + }, | ||
| 53 | + { | ||
| 54 | + test: /\.less$/, | ||
| 55 | + use: ['vue-style-loader', 'css-loader', 'less-loader'] | ||
| 56 | + }, | ||
| 57 | + { | ||
| 58 | + test: /\.css$/, | ||
| 59 | + use: ['vue-style-loader', 'css-loader'] | ||
| 60 | + }, | ||
| 61 | + { | ||
| 62 | + test: /\.html$/, | ||
| 63 | + use: 'vue-html-loader' | ||
| 64 | + }, | ||
| 65 | + { | ||
| 66 | + test: /\.js$/, | ||
| 67 | + use: 'babel-loader', | ||
| 68 | + exclude: /node_modules/ | ||
| 69 | + }, | ||
| 70 | + { | ||
| 71 | + test: /\.node$/, | ||
| 72 | + use: 'node-loader' | ||
| 73 | + }, | ||
| 74 | + { | ||
| 75 | + test: /\.vue$/, | ||
| 76 | + use: { | ||
| 77 | + loader: 'vue-loader', | ||
| 78 | + options: { | ||
| 79 | + extractCSS: process.env.NODE_ENV === 'production', | ||
| 80 | + loaders: { | ||
| 81 | + sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1', | ||
| 82 | + scss: 'vue-style-loader!css-loader!sass-loader', | ||
| 83 | + less: 'vue-style-loader!css-loader!less-loader' | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + }, | ||
| 88 | + { | ||
| 89 | + test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, | ||
| 90 | + use: { | ||
| 91 | + loader: 'url-loader', | ||
| 92 | + query: { | ||
| 93 | + limit: 10000, | ||
| 94 | + name: 'imgs/[name]--[folder].[ext]' | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + }, | ||
| 98 | + { | ||
| 99 | + test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, | ||
| 100 | + loader: 'url-loader', | ||
| 101 | + options: { | ||
| 102 | + limit: 10000, | ||
| 103 | + name: 'media/[name]--[folder].[ext]' | ||
| 104 | + } | ||
| 105 | + }, | ||
| 106 | + { | ||
| 107 | + test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, | ||
| 108 | + use: { | ||
| 109 | + loader: 'url-loader', | ||
| 110 | + query: { | ||
| 111 | + limit: 10000, | ||
| 112 | + name: 'fonts/[name]--[folder].[ext]' | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + ] | ||
| 117 | + }, | ||
| 118 | + node: { | ||
| 119 | + __dirname: process.env.NODE_ENV !== 'production', | ||
| 120 | + __filename: process.env.NODE_ENV !== 'production' | ||
| 121 | + }, | ||
| 122 | + plugins: [ | ||
| 123 | + new VueLoaderPlugin(), | ||
| 124 | + new MiniCssExtractPlugin({filename: 'styles.css'}), | ||
| 125 | + new HtmlWebpackPlugin({ | ||
| 126 | + filename: 'index.html', | ||
| 127 | + template: path.resolve(__dirname, '../src/index.ejs'), | ||
| 128 | + minify: { | ||
| 129 | + collapseWhitespace: true, | ||
| 130 | + removeAttributeQuotes: true, | ||
| 131 | + removeComments: true | ||
| 132 | + }, | ||
| 133 | + nodeModules: process.env.NODE_ENV !== 'production' | ||
| 134 | + ? path.resolve(__dirname, '../node_modules') | ||
| 135 | + : false | ||
| 136 | + }), | ||
| 137 | + new webpack.HotModuleReplacementPlugin(), | ||
| 138 | + new webpack.NoEmitOnErrorsPlugin() | ||
| 139 | + ], | ||
| 140 | + output: { | ||
| 141 | + filename: '[name].js', | ||
| 142 | + libraryTarget: 'commonjs2', | ||
| 143 | + path: path.join(__dirname, '../dist/electron') | ||
| 144 | + }, | ||
| 145 | + resolve: { | ||
| 146 | + alias: { | ||
| 147 | + '@': path.join(__dirname, '../src/renderer'), | ||
| 148 | + 'vue$': 'vue/dist/vue.esm.js' | ||
| 149 | + }, | ||
| 150 | + extensions: ['.js', '.vue', '.json', '.css', '.node'] | ||
| 151 | + }, | ||
| 152 | + target: 'electron-renderer' | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +/** | ||
| 156 | + * Adjust rendererConfig for development settings | ||
| 157 | + */ | ||
| 158 | +if (process.env.NODE_ENV !== 'production') { | ||
| 159 | + rendererConfig.plugins.push( | ||
| 160 | + new webpack.DefinePlugin({ | ||
| 161 | + '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"` | ||
| 162 | + }) | ||
| 163 | + ) | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +/** | ||
| 167 | + * Adjust rendererConfig for production settings | ||
| 168 | + */ | ||
| 169 | +if (process.env.NODE_ENV === 'production') { | ||
| 170 | + rendererConfig.devtool = '' | ||
| 171 | + | ||
| 172 | + rendererConfig.plugins.push( | ||
| 173 | + new BabiliWebpackPlugin(), | ||
| 174 | + new CopyWebpackPlugin([ | ||
| 175 | + { | ||
| 176 | + from: path.join(__dirname, '../static'), | ||
| 177 | + to: path.join(__dirname, '../dist/electron/static'), | ||
| 178 | + ignore: ['.*'] | ||
| 179 | + } | ||
| 180 | + ]), | ||
| 181 | + new webpack.DefinePlugin({ | ||
| 182 | + 'process.env.NODE_ENV': '"production"' | ||
| 183 | + }), | ||
| 184 | + new webpack.LoaderOptionsPlugin({ | ||
| 185 | + minimize: true | ||
| 186 | + }) | ||
| 187 | + ) | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +module.exports = rendererConfig |
.electron-vue/webpack.web.config.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +process.env.BABEL_ENV = 'web' | ||
| 4 | + | ||
| 5 | +const path = require('path') | ||
| 6 | +const webpack = require('webpack') | ||
| 7 | + | ||
| 8 | +const BabiliWebpackPlugin = require('babili-webpack-plugin') | ||
| 9 | +const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
| 10 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin') | ||
| 11 | +const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
| 12 | +const { VueLoaderPlugin } = require('vue-loader') | ||
| 13 | + | ||
| 14 | +let webConfig = { | ||
| 15 | + devtool: '#cheap-module-eval-source-map', | ||
| 16 | + entry: { | ||
| 17 | + web: path.join(__dirname, '../src/renderer/main.js') | ||
| 18 | + }, | ||
| 19 | + module: { | ||
| 20 | + rules: [ | ||
| 21 | + { | ||
| 22 | + test: /\.(js|vue)$/, | ||
| 23 | + enforce: 'pre', | ||
| 24 | + exclude: /node_modules/, | ||
| 25 | + use: { | ||
| 26 | + loader: 'eslint-loader', | ||
| 27 | + options: { | ||
| 28 | + formatter: require('eslint-friendly-formatter') | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + }, | ||
| 32 | + { | ||
| 33 | + test: /\.scss$/, | ||
| 34 | + use: ['vue-style-loader', 'css-loader', 'sass-loader'] | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + test: /\.sass$/, | ||
| 38 | + use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax'] | ||
| 39 | + }, | ||
| 40 | + { | ||
| 41 | + test: /\.less$/, | ||
| 42 | + use: ['vue-style-loader', 'css-loader', 'less-loader'] | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + test: /\.css$/, | ||
| 46 | + use: ['vue-style-loader', 'css-loader'] | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + test: /\.html$/, | ||
| 50 | + use: 'vue-html-loader' | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + test: /\.js$/, | ||
| 54 | + use: 'babel-loader', | ||
| 55 | + include: [ path.resolve(__dirname, '../src/renderer') ], | ||
| 56 | + exclude: /node_modules/ | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + test: /\.vue$/, | ||
| 60 | + use: { | ||
| 61 | + loader: 'vue-loader', | ||
| 62 | + options: { | ||
| 63 | + extractCSS: true, | ||
| 64 | + loaders: { | ||
| 65 | + sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1', | ||
| 66 | + scss: 'vue-style-loader!css-loader!sass-loader', | ||
| 67 | + less: 'vue-style-loader!css-loader!less-loader' | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + }, | ||
| 72 | + { | ||
| 73 | + test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, | ||
| 74 | + use: { | ||
| 75 | + loader: 'url-loader', | ||
| 76 | + query: { | ||
| 77 | + limit: 10000, | ||
| 78 | + name: 'imgs/[name].[ext]' | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + }, | ||
| 82 | + { | ||
| 83 | + test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, | ||
| 84 | + use: { | ||
| 85 | + loader: 'url-loader', | ||
| 86 | + query: { | ||
| 87 | + limit: 10000, | ||
| 88 | + name: 'fonts/[name].[ext]' | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + ] | ||
| 93 | + }, | ||
| 94 | + plugins: [ | ||
| 95 | + new VueLoaderPlugin(), | ||
| 96 | + new MiniCssExtractPlugin({filename: 'styles.css'}), | ||
| 97 | + new HtmlWebpackPlugin({ | ||
| 98 | + filename: 'index.html', | ||
| 99 | + template: path.resolve(__dirname, '../src/index.ejs'), | ||
| 100 | + minify: { | ||
| 101 | + collapseWhitespace: true, | ||
| 102 | + removeAttributeQuotes: true, | ||
| 103 | + removeComments: true | ||
| 104 | + }, | ||
| 105 | + nodeModules: false | ||
| 106 | + }), | ||
| 107 | + new webpack.DefinePlugin({ | ||
| 108 | + 'process.env.IS_WEB': 'true' | ||
| 109 | + }), | ||
| 110 | + new webpack.HotModuleReplacementPlugin(), | ||
| 111 | + new webpack.NoEmitOnErrorsPlugin() | ||
| 112 | + ], | ||
| 113 | + output: { | ||
| 114 | + filename: '[name].js', | ||
| 115 | + path: path.join(__dirname, '../dist/web') | ||
| 116 | + }, | ||
| 117 | + resolve: { | ||
| 118 | + alias: { | ||
| 119 | + '@': path.join(__dirname, '../src/renderer'), | ||
| 120 | + 'vue$': 'vue/dist/vue.esm.js' | ||
| 121 | + }, | ||
| 122 | + extensions: ['.js', '.vue', '.json', '.css'] | ||
| 123 | + }, | ||
| 124 | + target: 'web' | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +/** | ||
| 128 | + * Adjust webConfig for production settings | ||
| 129 | + */ | ||
| 130 | +if (process.env.NODE_ENV === 'production') { | ||
| 131 | + webConfig.devtool = '' | ||
| 132 | + | ||
| 133 | + webConfig.plugins.push( | ||
| 134 | + new BabiliWebpackPlugin(), | ||
| 135 | + new CopyWebpackPlugin([ | ||
| 136 | + { | ||
| 137 | + from: path.join(__dirname, '../static'), | ||
| 138 | + to: path.join(__dirname, '../dist/web/static'), | ||
| 139 | + ignore: ['.*'] | ||
| 140 | + } | ||
| 141 | + ]), | ||
| 142 | + new webpack.DefinePlugin({ | ||
| 143 | + 'process.env.NODE_ENV': '"production"' | ||
| 144 | + }), | ||
| 145 | + new webpack.LoaderOptionsPlugin({ | ||
| 146 | + minimize: true | ||
| 147 | + }) | ||
| 148 | + ) | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +module.exports = webConfig |
.eslintignore
0 → 100644
.eslintrc.js
0 → 100644
| 1 | +module.exports = { | ||
| 2 | + root: true, | ||
| 3 | + parser: 'babel-eslint', | ||
| 4 | + parserOptions: { | ||
| 5 | + sourceType: 'module' | ||
| 6 | + }, | ||
| 7 | + env: { | ||
| 8 | + browser: true, | ||
| 9 | + node: true | ||
| 10 | + }, | ||
| 11 | + extends: 'standard', | ||
| 12 | + globals: { | ||
| 13 | + __static: true | ||
| 14 | + }, | ||
| 15 | + plugins: [ | ||
| 16 | + 'html' | ||
| 17 | + ], | ||
| 18 | + 'rules': { | ||
| 19 | + // allow paren-less arrow functions | ||
| 20 | + 'arrow-parens': 0, | ||
| 21 | + // allow async-await | ||
| 22 | + 'generator-star-spacing': 0, | ||
| 23 | + // allow debugger during development | ||
| 24 | + 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 | ||
| 25 | + } | ||
| 26 | +} |
.gitignore
0 → 100644
.travis.yml
0 → 100644
| 1 | +# Commented sections below can be used to run tests on the CI server | ||
| 2 | +# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing | ||
| 3 | +osx_image: xcode8.3 | ||
| 4 | +sudo: required | ||
| 5 | +dist: trusty | ||
| 6 | +language: c | ||
| 7 | +matrix: | ||
| 8 | + include: | ||
| 9 | + - os: osx | ||
| 10 | + - os: linux | ||
| 11 | + env: CC=clang CXX=clang++ npm_config_clang=1 | ||
| 12 | + compiler: clang | ||
| 13 | +cache: | ||
| 14 | + directories: | ||
| 15 | + - node_modules | ||
| 16 | + - "$HOME/.electron" | ||
| 17 | + - "$HOME/.cache" | ||
| 18 | +addons: | ||
| 19 | + apt: | ||
| 20 | + packages: | ||
| 21 | + - libgnome-keyring-dev | ||
| 22 | + - icnsutils | ||
| 23 | + #- xvfb | ||
| 24 | +before_install: | ||
| 25 | +- mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([ | ||
| 26 | + "$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz | ||
| 27 | + | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull | ||
| 28 | +- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi | ||
| 29 | +install: | ||
| 30 | +#- export DISPLAY=':99.0' | ||
| 31 | +#- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & | ||
| 32 | +- nvm install 7 | ||
| 33 | +- curl -o- -L https://yarnpkg.com/install.sh | bash | ||
| 34 | +- source ~/.bashrc | ||
| 35 | +- npm install -g xvfb-maybe | ||
| 36 | +- yarn | ||
| 37 | +script: | ||
| 38 | +#- xvfb-maybe node_modules/.bin/karma start test/unit/karma.conf.js | ||
| 39 | +#- yarn run pack && xvfb-maybe node_modules/.bin/mocha test/e2e | ||
| 40 | +- yarn run build | ||
| 41 | +branches: | ||
| 42 | + only: | ||
| 43 | + - master |
appveyor.yml
0 → 100644
| 1 | +# Commented sections below can be used to run tests on the CI server | ||
| 2 | +# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing | ||
| 3 | +version: 0.1.{build} | ||
| 4 | + | ||
| 5 | +branches: | ||
| 6 | + only: | ||
| 7 | + - master | ||
| 8 | + | ||
| 9 | +image: Visual Studio 2017 | ||
| 10 | +platform: | ||
| 11 | + - x64 | ||
| 12 | + | ||
| 13 | +cache: | ||
| 14 | + - node_modules | ||
| 15 | + - '%APPDATA%\npm-cache' | ||
| 16 | + - '%USERPROFILE%\.electron' | ||
| 17 | + - '%USERPROFILE%\AppData\Local\Yarn\cache' | ||
| 18 | + | ||
| 19 | +init: | ||
| 20 | + - git config --global core.autocrlf input | ||
| 21 | + | ||
| 22 | +install: | ||
| 23 | + - ps: Install-Product node 8 x64 | ||
| 24 | + - git reset --hard HEAD | ||
| 25 | + - yarn | ||
| 26 | + - node --version | ||
| 27 | + | ||
| 28 | +build_script: | ||
| 29 | + #- yarn test | ||
| 30 | + - yarn build | ||
| 31 | + | ||
| 32 | +test: off |
build/icons/256x256.png
0 → 100644
34.7 KB
build/icons/icon.icns
0 → 100644
此文件类型无法预览
build/icons/icon.ico
0 → 100644
此文件类型无法预览
config/dev.env.js
0 → 100644
config/index.js
0 → 100644
config/prod.env.js
0 → 100644
dist/electron/.gitkeep
0 → 100644
文件属性发生变化
dist/web/.gitkeep
0 → 100644
文件属性发生变化
package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "name": "my-project", | ||
| 3 | + "version": "0.0.1", | ||
| 4 | + "author": "fengjie <fengjie1438@f-road.com.cn>", | ||
| 5 | + "description": "An electron-vue project", | ||
| 6 | + "license": null, | ||
| 7 | + "main": "./dist/electron/main.js", | ||
| 8 | + "scripts": { | ||
| 9 | + "build": "node .electron-vue/build.js && electron-builder", | ||
| 10 | + "build:dir": "node .electron-vue/build.js && electron-builder --dir", | ||
| 11 | + "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js", | ||
| 12 | + "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js", | ||
| 13 | + "dev": "node .electron-vue/dev-runner.js", | ||
| 14 | + "e2e": "npm run pack && mocha test/e2e", | ||
| 15 | + "lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src test", | ||
| 16 | + "lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src test", | ||
| 17 | + "pack": "npm run pack:main && npm run pack:renderer", | ||
| 18 | + "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js", | ||
| 19 | + "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js", | ||
| 20 | + "test": "npm run unit && npm run e2e", | ||
| 21 | + "unit": "karma start test/unit/karma.conf.js", | ||
| 22 | + "postinstall": "npm run lint:fix" | ||
| 23 | + }, | ||
| 24 | + "build": { | ||
| 25 | + "productName": "my-project", | ||
| 26 | + "appId": "com.example.yourapp", | ||
| 27 | + "directories": { | ||
| 28 | + "output": "build" | ||
| 29 | + }, | ||
| 30 | + "files": [ | ||
| 31 | + "dist/electron/**/*" | ||
| 32 | + ], | ||
| 33 | + "dmg": { | ||
| 34 | + "contents": [ | ||
| 35 | + { | ||
| 36 | + "x": 410, | ||
| 37 | + "y": 150, | ||
| 38 | + "type": "link", | ||
| 39 | + "path": "/Applications" | ||
| 40 | + }, | ||
| 41 | + { | ||
| 42 | + "x": 130, | ||
| 43 | + "y": 150, | ||
| 44 | + "type": "file" | ||
| 45 | + } | ||
| 46 | + ] | ||
| 47 | + }, | ||
| 48 | + "mac": { | ||
| 49 | + "icon": "build/icons/icon.icns" | ||
| 50 | + }, | ||
| 51 | + "win": { | ||
| 52 | + "icon": "build/icons/icon.ico" | ||
| 53 | + }, | ||
| 54 | + "linux": { | ||
| 55 | + "icon": "build/icons" | ||
| 56 | + } | ||
| 57 | + }, | ||
| 58 | + "dependencies": { | ||
| 59 | + "axios": "^0.18.0", | ||
| 60 | + "element-ui": "^2.6.1", | ||
| 61 | + "nedb": "^1.8.0", | ||
| 62 | + "vue": "^2.5.16", | ||
| 63 | + "vue-electron": "^1.0.6", | ||
| 64 | + "vue-router": "^3.0.1", | ||
| 65 | + "vuex": "^3.0.1", | ||
| 66 | + "vuex-electron": "^1.0.0" | ||
| 67 | + }, | ||
| 68 | + "devDependencies": { | ||
| 69 | + "ajv": "^6.5.0", | ||
| 70 | + "babel-core": "^6.26.3", | ||
| 71 | + "babel-loader": "^7.1.4", | ||
| 72 | + "babel-plugin-transform-runtime": "^6.23.0", | ||
| 73 | + "babel-preset-env": "^1.7.0", | ||
| 74 | + "babel-preset-stage-0": "^6.24.1", | ||
| 75 | + "babel-register": "^6.26.0", | ||
| 76 | + "babili-webpack-plugin": "^0.1.2", | ||
| 77 | + "cfonts": "^2.1.2", | ||
| 78 | + "chalk": "^2.4.1", | ||
| 79 | + "copy-webpack-plugin": "^4.5.1", | ||
| 80 | + "cross-env": "^5.1.6", | ||
| 81 | + "css-loader": "^0.28.11", | ||
| 82 | + "del": "^3.0.0", | ||
| 83 | + "devtron": "^1.4.0", | ||
| 84 | + "electron": "^2.0.4", | ||
| 85 | + "electron-debug": "^1.5.0", | ||
| 86 | + "electron-devtools-installer": "^2.2.4", | ||
| 87 | + "electron-builder": "^20.19.2", | ||
| 88 | + "babel-eslint": "^8.2.3", | ||
| 89 | + "eslint": "^4.19.1", | ||
| 90 | + "eslint-friendly-formatter": "^4.0.1", | ||
| 91 | + "eslint-loader": "^2.0.0", | ||
| 92 | + "eslint-plugin-html": "^4.0.3", | ||
| 93 | + "eslint-config-standard": "^11.0.0", | ||
| 94 | + "eslint-plugin-import": "^2.12.0", | ||
| 95 | + "eslint-plugin-node": "^6.0.1", | ||
| 96 | + "eslint-plugin-promise": "^3.8.0", | ||
| 97 | + "eslint-plugin-standard": "^3.1.0", | ||
| 98 | + "mini-css-extract-plugin": "0.4.0", | ||
| 99 | + "file-loader": "^1.1.11", | ||
| 100 | + "html-webpack-plugin": "^3.2.0", | ||
| 101 | + "inject-loader": "^4.0.1", | ||
| 102 | + "karma": "^2.0.2", | ||
| 103 | + "karma-chai": "^0.1.0", | ||
| 104 | + "karma-coverage": "^1.1.2", | ||
| 105 | + "karma-electron": "^6.0.0", | ||
| 106 | + "karma-mocha": "^1.3.0", | ||
| 107 | + "karma-sourcemap-loader": "^0.3.7", | ||
| 108 | + "karma-spec-reporter": "^0.0.32", | ||
| 109 | + "karma-webpack": "^3.0.0", | ||
| 110 | + "require-dir": "^1.0.0", | ||
| 111 | + "spectron": "^3.8.0", | ||
| 112 | + "babel-plugin-istanbul": "^4.1.6", | ||
| 113 | + "chai": "^4.1.2", | ||
| 114 | + "mocha": "^5.2.0", | ||
| 115 | + "multispinner": "^0.2.1", | ||
| 116 | + "node-loader": "^0.6.0", | ||
| 117 | + "node-sass": "^4.9.2", | ||
| 118 | + "sass-loader": "^7.0.3", | ||
| 119 | + "style-loader": "^0.21.0", | ||
| 120 | + "url-loader": "^1.0.1", | ||
| 121 | + "vue-html-loader": "^1.2.4", | ||
| 122 | + "vue-loader": "^15.2.4", | ||
| 123 | + "vue-style-loader": "^4.1.0", | ||
| 124 | + "vue-template-compiler": "^2.5.16", | ||
| 125 | + "webpack-cli": "^3.0.8", | ||
| 126 | + "webpack": "^4.15.1", | ||
| 127 | + "webpack-dev-server": "^3.1.4", | ||
| 128 | + "webpack-hot-middleware": "^2.22.2", | ||
| 129 | + "webpack-merge": "^4.1.3" | ||
| 130 | + } | ||
| 131 | +} |
src/index.ejs
0 → 100644
| 1 | +<!DOCTYPE html> | ||
| 2 | +<html> | ||
| 3 | + <head> | ||
| 4 | + <meta charset="utf-8"> | ||
| 5 | + <title>my-project</title> | ||
| 6 | + <% if (htmlWebpackPlugin.options.nodeModules) { %> | ||
| 7 | + <!-- Add `node_modules/` to global paths so `require` works properly in development --> | ||
| 8 | + <script> | ||
| 9 | + require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>') | ||
| 10 | + </script> | ||
| 11 | + <% } %> | ||
| 12 | + </head> | ||
| 13 | + <body> | ||
| 14 | + <div id="app"></div> | ||
| 15 | + <!-- Set `__static` path to static files in production --> | ||
| 16 | + <% if (!process.browser) { %> | ||
| 17 | + <script> | ||
| 18 | + if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') | ||
| 19 | + </script> | ||
| 20 | + <% } %> | ||
| 21 | + | ||
| 22 | + <!-- webpack builds are automatically injected --> | ||
| 23 | + </body> | ||
| 24 | +</html> |
src/main/index.dev.js
0 → 100644
| 1 | +/** | ||
| 2 | + * This file is used specifically and only for development. It installs | ||
| 3 | + * `electron-debug` & `vue-devtools`. There shouldn't be any need to | ||
| 4 | + * modify this file, but it can be used to extend your development | ||
| 5 | + * environment. | ||
| 6 | + */ | ||
| 7 | + | ||
| 8 | +/* eslint-disable */ | ||
| 9 | + | ||
| 10 | +// Install `electron-debug` with `devtron` | ||
| 11 | +require('electron-debug')({ showDevTools: true }) | ||
| 12 | + | ||
| 13 | +// Install `vue-devtools` | ||
| 14 | +require('electron').app.on('ready', () => { | ||
| 15 | + let installExtension = require('electron-devtools-installer') | ||
| 16 | + installExtension.default(installExtension.VUEJS_DEVTOOLS) | ||
| 17 | + .then(() => {}) | ||
| 18 | + .catch(err => { | ||
| 19 | + console.log('Unable to install `vue-devtools`: \n', err) | ||
| 20 | + }) | ||
| 21 | +}) | ||
| 22 | + | ||
| 23 | +// Require `main` process to boot app | ||
| 24 | +require('./index') | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
src/main/index.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +import { | ||
| 4 | + app, | ||
| 5 | + BrowserWindow, | ||
| 6 | + Menu | ||
| 7 | +} from 'electron' | ||
| 8 | +import '../renderer/store' | ||
| 9 | +import menuconfig from './menu' | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Set `__static` path to static files in production | ||
| 13 | + * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html | ||
| 14 | + */ | ||
| 15 | +if (process.env.NODE_ENV !== 'development') { | ||
| 16 | + global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +let mainWindow | ||
| 20 | +const winURL = process.env.NODE_ENV === 'development' | ||
| 21 | + ? `http://localhost:9080` | ||
| 22 | + : `file://${__dirname}/index.html` | ||
| 23 | + | ||
| 24 | +function createWindow () { | ||
| 25 | + /** | ||
| 26 | + * Initial window options | ||
| 27 | + */ | ||
| 28 | + mainWindow = new BrowserWindow({ | ||
| 29 | + height: 563, | ||
| 30 | + useContentSize: true, | ||
| 31 | + width: 1000, | ||
| 32 | + show: false, | ||
| 33 | + backgroundColor: '#fffff' | ||
| 34 | + }) | ||
| 35 | + | ||
| 36 | + mainWindow.once('ready-to-show', () => { | ||
| 37 | + mainWindow.show() | ||
| 38 | + }) | ||
| 39 | + | ||
| 40 | + const menu = Menu.buildFromTemplate(menuconfig) | ||
| 41 | + Menu.setApplicationMenu(menu) | ||
| 42 | + mainWindow.loadURL(winURL) | ||
| 43 | + | ||
| 44 | + mainWindow.on('closed', () => { | ||
| 45 | + mainWindow = null | ||
| 46 | + }) | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +app.on('ready', createWindow) | ||
| 50 | + | ||
| 51 | +app.on('window-all-closed', () => { | ||
| 52 | + if (process.platform !== 'darwin') { | ||
| 53 | + app.quit() | ||
| 54 | + } | ||
| 55 | +}) | ||
| 56 | + | ||
| 57 | +app.on('activate', () => { | ||
| 58 | + if (mainWindow === null) { | ||
| 59 | + createWindow() | ||
| 60 | + } | ||
| 61 | +}) | ||
| 62 | + | ||
| 63 | +/** | ||
| 64 | + * Auto Updater | ||
| 65 | + * | ||
| 66 | + * Uncomment the following code below and install `electron-updater` to | ||
| 67 | + * support auto updating. Code Signing with a valid certificate is required. | ||
| 68 | + * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating | ||
| 69 | + */ | ||
| 70 | + | ||
| 71 | +/* | ||
| 72 | +import { autoUpdater } from 'electron-updater' | ||
| 73 | + | ||
| 74 | +autoUpdater.on('update-downloaded', () => { | ||
| 75 | + autoUpdater.quitAndInstall() | ||
| 76 | +}) | ||
| 77 | + | ||
| 78 | +app.on('ready', () => { | ||
| 79 | + if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates() | ||
| 80 | +}) | ||
| 81 | + */ |
src/main/menu.js
0 → 100644
| 1 | +// 这里是定义菜单的地方,详情请查看 https://electronjs.org/docs/api/menu | ||
| 2 | +const menu = [{ | ||
| 3 | + label: '文档操作', | ||
| 4 | + submenu: [{ | ||
| 5 | + label: '撤销', | ||
| 6 | + accelerator: 'CmdOrCtrl+Z', | ||
| 7 | + role: 'undo' | ||
| 8 | + }, { | ||
| 9 | + label: '复制', | ||
| 10 | + accelerator: 'CmdOrCtrl+C', | ||
| 11 | + role: 'copy' | ||
| 12 | + }] | ||
| 13 | +}, | ||
| 14 | +{ | ||
| 15 | + label: '设置', | ||
| 16 | + submenu: [{ | ||
| 17 | + label: '快速重启', | ||
| 18 | + accelerator: 'F5', | ||
| 19 | + role: 'reload' | ||
| 20 | + }, { | ||
| 21 | + label: '退出', | ||
| 22 | + accelerator: 'CmdOrCtrl+F4', | ||
| 23 | + role: 'close' | ||
| 24 | + }] | ||
| 25 | +}] | ||
| 26 | +export default menu |
src/renderer/App.vue
0 → 100644
src/renderer/assets/.gitkeep
0 → 100644
文件属性发生变化
src/renderer/assets/logo.png
0 → 100644
60.4 KB
src/renderer/components/LandingPage.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div id="wrapper"> | ||
| 3 | + <img id="logo" src="~@/assets/logo.png" alt="electron-vue"> | ||
| 4 | + <main> | ||
| 5 | + <div class="left-side"> | ||
| 6 | + <span class="title"> | ||
| 7 | + Welcome to your new project! | ||
| 8 | + </span> | ||
| 9 | + <system-information></system-information> | ||
| 10 | + </div> | ||
| 11 | + | ||
| 12 | + <div class="right-side"> | ||
| 13 | + <div class="doc"> | ||
| 14 | + <div class="title alt">Other Documentation</div> | ||
| 15 | + <el-button type="primary" round @click="open()">控制台打印</el-button> | ||
| 16 | + <el-button type="primary" round>element按钮示例</el-button> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | + </main> | ||
| 20 | + </div> | ||
| 21 | +</template> | ||
| 22 | + | ||
| 23 | +<script> | ||
| 24 | + import SystemInformation from './LandingPage/SystemInformation' | ||
| 25 | + | ||
| 26 | + export default { | ||
| 27 | + name: 'landing-page', | ||
| 28 | + components: { SystemInformation }, | ||
| 29 | + methods: { | ||
| 30 | + open (link) { | ||
| 31 | + console.log(this.$electron) | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | +</script> | ||
| 36 | + | ||
| 37 | +<style> | ||
| 38 | + | ||
| 39 | + * { | ||
| 40 | + box-sizing: border-box; | ||
| 41 | + margin: 0; | ||
| 42 | + padding: 0; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + body { font-family: 'Source Sans Pro', sans-serif; } | ||
| 46 | + | ||
| 47 | + #wrapper { | ||
| 48 | + background: | ||
| 49 | + radial-gradient( | ||
| 50 | + ellipse at top left, | ||
| 51 | + rgba(255, 255, 255, 1) 40%, | ||
| 52 | + rgba(229, 229, 229, .9) 100% | ||
| 53 | + ); | ||
| 54 | + height: 100vh; | ||
| 55 | + padding: 60px 80px; | ||
| 56 | + width: 100vw; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + #logo { | ||
| 60 | + height: auto; | ||
| 61 | + margin-bottom: 20px; | ||
| 62 | + width: 420px; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + main { | ||
| 66 | + display: flex; | ||
| 67 | + justify-content: space-between; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + main > div { flex-basis: 50%; } | ||
| 71 | + | ||
| 72 | + .left-side { | ||
| 73 | + display: flex; | ||
| 74 | + flex-direction: column; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + .welcome { | ||
| 78 | + color: #555; | ||
| 79 | + font-size: 23px; | ||
| 80 | + margin-bottom: 10px; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + .title { | ||
| 84 | + color: #2c3e50; | ||
| 85 | + font-size: 20px; | ||
| 86 | + font-weight: bold; | ||
| 87 | + margin-bottom: 6px; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + .title.alt { | ||
| 91 | + font-size: 18px; | ||
| 92 | + margin-bottom: 10px; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + .doc p { | ||
| 96 | + color: black; | ||
| 97 | + margin-bottom: 10px; | ||
| 98 | + } | ||
| 99 | +</style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +<template> | ||
| 2 | + <div> | ||
| 3 | + <div class="title">Information</div> | ||
| 4 | + <div class="items"> | ||
| 5 | + <div class="item"> | ||
| 6 | + <div class="name">Path:</div> | ||
| 7 | + <div class="value">{{ path }}</div> | ||
| 8 | + </div> | ||
| 9 | + <div class="item"> | ||
| 10 | + <div class="name">Route Name:</div> | ||
| 11 | + <div class="value">{{ name }}</div> | ||
| 12 | + </div> | ||
| 13 | + <div class="item"> | ||
| 14 | + <div class="name">Vue.js:</div> | ||
| 15 | + <div class="value">{{ vue }}</div> | ||
| 16 | + </div> | ||
| 17 | + <div class="item"> | ||
| 18 | + <div class="name">Electron:</div> | ||
| 19 | + <div class="value">{{ electron }}</div> | ||
| 20 | + </div> | ||
| 21 | + <div class="item"> | ||
| 22 | + <div class="name">Node:</div> | ||
| 23 | + <div class="value">{{ node }}</div> | ||
| 24 | + </div> | ||
| 25 | + <div class="item"> | ||
| 26 | + <div class="name">Platform:</div> | ||
| 27 | + <div class="value">{{ platform }}</div> | ||
| 28 | + </div> | ||
| 29 | + </div> | ||
| 30 | + </div> | ||
| 31 | +</template> | ||
| 32 | + | ||
| 33 | +<script> | ||
| 34 | + export default { | ||
| 35 | + data () { | ||
| 36 | + return { | ||
| 37 | + electron: process.versions.electron, | ||
| 38 | + name: this.$route.name, | ||
| 39 | + node: process.versions.node, | ||
| 40 | + path: this.$route.path, | ||
| 41 | + platform: require('os').platform(), | ||
| 42 | + vue: require('vue/package.json').version | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | +</script> | ||
| 47 | + | ||
| 48 | +<style scoped> | ||
| 49 | + .title { | ||
| 50 | + color: #888; | ||
| 51 | + font-size: 18px; | ||
| 52 | + font-weight: initial; | ||
| 53 | + letter-spacing: .25px; | ||
| 54 | + margin-top: 10px; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + .items { margin-top: 8px; } | ||
| 58 | + | ||
| 59 | + .item { | ||
| 60 | + display: flex; | ||
| 61 | + margin-bottom: 6px; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + .item .name { | ||
| 65 | + color: #6a6a6a; | ||
| 66 | + margin-right: 6px; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + .item .value { | ||
| 70 | + color: #35495e; | ||
| 71 | + font-weight: bold; | ||
| 72 | + } | ||
| 73 | +</style> |
src/renderer/main.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | + | ||
| 3 | +import App from './App' | ||
| 4 | +import router from './router' | ||
| 5 | +import store from './store' | ||
| 6 | +// 引用nedb做本地存储 | ||
| 7 | +import db from './utils/db' | ||
| 8 | +// 引用element | ||
| 9 | +import ElementUI from 'element-ui' | ||
| 10 | +import 'element-ui/lib/theme-chalk/index.css' | ||
| 11 | + | ||
| 12 | +if (!process.env.IS_WEB) Vue.use(require('vue-electron')) | ||
| 13 | + | ||
| 14 | +Vue.use(ElementUI) | ||
| 15 | + | ||
| 16 | +Vue.config.productionTip = false | ||
| 17 | +Vue.prototype.$db = db | ||
| 18 | +/* eslint-disable no-new */ | ||
| 19 | +new Vue({ | ||
| 20 | + components: { | ||
| 21 | + App | ||
| 22 | + }, | ||
| 23 | + router, | ||
| 24 | + store, | ||
| 25 | + template: '<App/>' | ||
| 26 | +}).$mount('#app') |
src/renderer/router/index.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | +import Router from 'vue-router' | ||
| 3 | + | ||
| 4 | +Vue.use(Router) | ||
| 5 | + | ||
| 6 | +export default new Router({ | ||
| 7 | + routes: [ | ||
| 8 | + { | ||
| 9 | + path: '/', | ||
| 10 | + name: 'landing-page', | ||
| 11 | + component: require('@/components/LandingPage').default | ||
| 12 | + }, | ||
| 13 | + { | ||
| 14 | + path: '*', | ||
| 15 | + redirect: '/' | ||
| 16 | + } | ||
| 17 | + ] | ||
| 18 | +}) |
src/renderer/store/index.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | +import Vuex from 'vuex' | ||
| 3 | + | ||
| 4 | +import { createPersistedState, createSharedMutations } from 'vuex-electron' | ||
| 5 | + | ||
| 6 | +import modules from './modules' | ||
| 7 | + | ||
| 8 | +Vue.use(Vuex) | ||
| 9 | + | ||
| 10 | +export default new Vuex.Store({ | ||
| 11 | + modules, | ||
| 12 | + plugins: [ | ||
| 13 | + createPersistedState(), | ||
| 14 | + createSharedMutations() | ||
| 15 | + ], | ||
| 16 | + strict: process.env.NODE_ENV !== 'production' | ||
| 17 | +}) |
src/renderer/store/modules/Counter.js
0 → 100644
| 1 | +const state = { | ||
| 2 | + main: 0 | ||
| 3 | +} | ||
| 4 | + | ||
| 5 | +const mutations = { | ||
| 6 | + DECREMENT_MAIN_COUNTER (state) { | ||
| 7 | + state.main-- | ||
| 8 | + }, | ||
| 9 | + INCREMENT_MAIN_COUNTER (state) { | ||
| 10 | + state.main++ | ||
| 11 | + } | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +const actions = { | ||
| 15 | + someAsyncTask ({ commit }) { | ||
| 16 | + // do something async | ||
| 17 | + commit('INCREMENT_MAIN_COUNTER') | ||
| 18 | + } | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +export default { | ||
| 22 | + state, | ||
| 23 | + mutations, | ||
| 24 | + actions | ||
| 25 | +} |
src/renderer/store/modules/index.js
0 → 100644
| 1 | +/** | ||
| 2 | + * The file enables `@/store/index.js` to import all vuex modules | ||
| 3 | + * in a one-shot manner. There should not be any reason to edit this file. | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +const files = require.context('.', false, /\.js$/) | ||
| 7 | +const modules = {} | ||
| 8 | + | ||
| 9 | +files.keys().forEach(key => { | ||
| 10 | + if (key === './index.js') return | ||
| 11 | + modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default | ||
| 12 | +}) | ||
| 13 | + | ||
| 14 | +export default modules |
src/renderer/utils/db.js
0 → 100644
src/renderer/utils/request.js
0 → 100644
| 1 | +import axios from 'axios' | ||
| 2 | +import { | ||
| 3 | + Message | ||
| 4 | +} from 'element-ui' | ||
| 5 | +const serves = axios.create({ | ||
| 6 | + baseURL: process.env.BASE_API, | ||
| 7 | + timeout: 5000 | ||
| 8 | +}) | ||
| 9 | + | ||
| 10 | +// 设置请求发送之前的拦截器 | ||
| 11 | +serves.interceptors.request.use(config => { | ||
| 12 | + // 设置发送之前数据需要做什么处理 | ||
| 13 | + return config | ||
| 14 | +}, err => Promise.reject(err)) | ||
| 15 | + | ||
| 16 | +// 设置请求接受拦截器 | ||
| 17 | +serves.interceptors.response.use(res => { | ||
| 18 | + // 设置接受数据之后,做什么处理 | ||
| 19 | + return res | ||
| 20 | +}, err => { | ||
| 21 | + // 判断请求异常信息中是否含有超时timeout字符串 | ||
| 22 | + if (err.message.includes('timeout')) { | ||
| 23 | + console.log('错误回调', err) | ||
| 24 | + Message.error('网络超时') | ||
| 25 | + } | ||
| 26 | + return Promise.reject(err) | ||
| 27 | +}) | ||
| 28 | + | ||
| 29 | +// 将serves抛出去 | ||
| 30 | +export default serves |
static/.gitkeep
0 → 100644
文件属性发生变化
test/.eslintrc
0 → 100644
test/e2e/index.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +// Set BABEL_ENV to use proper env config | ||
| 4 | +process.env.BABEL_ENV = 'test' | ||
| 5 | + | ||
| 6 | +// Enable use of ES6+ on required files | ||
| 7 | +require('babel-register')({ | ||
| 8 | + ignore: /node_modules/ | ||
| 9 | +}) | ||
| 10 | + | ||
| 11 | +// Attach Chai APIs to global scope | ||
| 12 | +const { expect, should, assert } = require('chai') | ||
| 13 | +global.expect = expect | ||
| 14 | +global.should = should | ||
| 15 | +global.assert = assert | ||
| 16 | + | ||
| 17 | +// Require all JS files in `./specs` for Mocha to consume | ||
| 18 | +require('require-dir')('./specs') |
test/e2e/specs/Launch.spec.js
0 → 100644
| 1 | +import utils from '../utils' | ||
| 2 | + | ||
| 3 | +describe('Launch', function () { | ||
| 4 | + beforeEach(utils.beforeEach) | ||
| 5 | + afterEach(utils.afterEach) | ||
| 6 | + | ||
| 7 | + it('shows the proper application title', function () { | ||
| 8 | + return this.app.client.getTitle() | ||
| 9 | + .then(title => { | ||
| 10 | + expect(title).to.equal('my-project') | ||
| 11 | + }) | ||
| 12 | + }) | ||
| 13 | +}) |
test/e2e/utils.js
0 → 100644
| 1 | +import electron from 'electron' | ||
| 2 | +import { Application } from 'spectron' | ||
| 3 | + | ||
| 4 | +export default { | ||
| 5 | + afterEach () { | ||
| 6 | + this.timeout(10000) | ||
| 7 | + | ||
| 8 | + if (this.app && this.app.isRunning()) { | ||
| 9 | + return this.app.stop() | ||
| 10 | + } | ||
| 11 | + }, | ||
| 12 | + beforeEach () { | ||
| 13 | + this.timeout(10000) | ||
| 14 | + this.app = new Application({ | ||
| 15 | + path: electron, | ||
| 16 | + args: ['dist/electron/main.js'], | ||
| 17 | + startTimeout: 10000, | ||
| 18 | + waitTimeout: 10000 | ||
| 19 | + }) | ||
| 20 | + | ||
| 21 | + return this.app.start() | ||
| 22 | + } | ||
| 23 | +} |
test/unit/index.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | +Vue.config.devtools = false | ||
| 3 | +Vue.config.productionTip = false | ||
| 4 | + | ||
| 5 | +// require all test files (files that ends with .spec.js) | ||
| 6 | +const testsContext = require.context('./specs', true, /\.spec$/) | ||
| 7 | +testsContext.keys().forEach(testsContext) | ||
| 8 | + | ||
| 9 | +// require all src files except main.js for coverage. | ||
| 10 | +// you can also change this to match only the subset of files that | ||
| 11 | +// you want coverage for. | ||
| 12 | +const srcContext = require.context('../../src/renderer', true, /^\.\/(?!main(\.js)?$)/) | ||
| 13 | +srcContext.keys().forEach(srcContext) |
test/unit/karma.conf.js
0 → 100644
| 1 | +'use strict' | ||
| 2 | + | ||
| 3 | +const path = require('path') | ||
| 4 | +const merge = require('webpack-merge') | ||
| 5 | +const webpack = require('webpack') | ||
| 6 | + | ||
| 7 | +const baseConfig = require('../../.electron-vue/webpack.renderer.config') | ||
| 8 | +const projectRoot = path.resolve(__dirname, '../../src/renderer') | ||
| 9 | + | ||
| 10 | +// Set BABEL_ENV to use proper preset config | ||
| 11 | +process.env.BABEL_ENV = 'test' | ||
| 12 | + | ||
| 13 | +let webpackConfig = merge(baseConfig, { | ||
| 14 | + devtool: '#inline-source-map', | ||
| 15 | + plugins: [ | ||
| 16 | + new webpack.DefinePlugin({ | ||
| 17 | + 'process.env.NODE_ENV': '"testing"' | ||
| 18 | + }) | ||
| 19 | + ] | ||
| 20 | +}) | ||
| 21 | + | ||
| 22 | +// don't treat dependencies as externals | ||
| 23 | +delete webpackConfig.entry | ||
| 24 | +delete webpackConfig.externals | ||
| 25 | +delete webpackConfig.output.libraryTarget | ||
| 26 | + | ||
| 27 | +// apply vue option to apply isparta-loader on js | ||
| 28 | +webpackConfig.module.rules | ||
| 29 | + .find(rule => rule.use.loader === 'vue-loader').use.options.loaders.js = 'babel-loader' | ||
| 30 | + | ||
| 31 | +module.exports = config => { | ||
| 32 | + config.set({ | ||
| 33 | + browsers: ['visibleElectron'], | ||
| 34 | + client: { | ||
| 35 | + useIframe: false | ||
| 36 | + }, | ||
| 37 | + coverageReporter: { | ||
| 38 | + dir: './coverage', | ||
| 39 | + reporters: [ | ||
| 40 | + { type: 'lcov', subdir: '.' }, | ||
| 41 | + { type: 'text-summary' } | ||
| 42 | + ] | ||
| 43 | + }, | ||
| 44 | + customLaunchers: { | ||
| 45 | + 'visibleElectron': { | ||
| 46 | + base: 'Electron', | ||
| 47 | + flags: ['--show'] | ||
| 48 | + } | ||
| 49 | + }, | ||
| 50 | + frameworks: ['mocha', 'chai'], | ||
| 51 | + files: ['./index.js'], | ||
| 52 | + preprocessors: { | ||
| 53 | + './index.js': ['webpack', 'sourcemap'] | ||
| 54 | + }, | ||
| 55 | + reporters: ['spec', 'coverage'], | ||
| 56 | + singleRun: true, | ||
| 57 | + webpack: webpackConfig, | ||
| 58 | + webpackMiddleware: { | ||
| 59 | + noInfo: true | ||
| 60 | + } | ||
| 61 | + }) | ||
| 62 | +} |
test/unit/specs/LandingPage.spec.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | +import LandingPage from '@/components/LandingPage' | ||
| 3 | + | ||
| 4 | +describe('LandingPage.vue', () => { | ||
| 5 | + it('should render correct contents', () => { | ||
| 6 | + const vm = new Vue({ | ||
| 7 | + el: document.createElement('div'), | ||
| 8 | + render: h => h(LandingPage) | ||
| 9 | + }).$mount() | ||
| 10 | + | ||
| 11 | + expect(vm.$el.querySelector('.title').textContent).to.contain('Welcome to your new project!') | ||
| 12 | + }) | ||
| 13 | +}) |
-
请 注册 或 登录 后发表评论