├── .gitignore ├── LICENSE ├── README.md ├── meta.js ├── package.json ├── scripts └── update-cube-version.js └── template ├── .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 └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package.json ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ └── HelloWorld.vue ├── main.js ├── router │ └── index.js └── theme.styl ├── static └── .gitkeep └── test ├── e2e ├── custom-assertions │ └── elementCount.js ├── nightwatch.conf.js ├── runner.js └── specs │ └── test.js └── unit ├── .eslintrc ├── index.js ├── jest.conf.js ├── karma.conf.js ├── setup.js └── specs └── HelloWorld.spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | docs/_book 4 | demo/ 5 | .idea/ 6 | bak/ 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 cube-ui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cube-template 2 | 3 | cube-ui template for Vue-cli 4 | 5 | 在 cube-template 中特殊的配置项。 6 | 7 | - Use post-compile? 8 | 9 | 后编译,详细文档 https://didi.github.io/cube-ui/#/zh-CN/docs/post-compile 10 | 11 | - Import type 12 | 13 | 引入类型,可以是: 14 | 15 | - 按需引入(推荐):https://didi.github.io/cube-ui/#/zh-CN/docs/quick-start#cube-按需引入-anchor 16 | - 全部引入:https://didi.github.io/cube-ui/#/zh-CN/docs/quick-start#cube-全部引入-anchor 17 | 18 | - Custom theme? 19 | 20 | 自定义主题,使用后编译的情况下可用;会在 `src/` 目录下创建一个 `theme.styl` 的文件,定义各种变量,参考 https://didi.github.io/cube-ui/#/zh-CN/docs/theme 21 | 22 | - Use rem layout? 23 | 24 | rem 布局,使用后编译的情况下可用;使用 [postcss-px2rem](https://github.com/songsiqi/px2rem-postcss) 插件完成 px 到 rem 的转换,如果要修改基准值,修改 `.postcssrc.js` 文件中的 "remUnit" 的值即可。 25 | 26 | - Use vw layout? 27 | 28 | vw 布局,使用后编译的情况下且不是 rem 布局的情况下可用;使用 [postcss-px-to-viewport](https://github.com/evrone/postcss-px-to-viewport) 插件完成 px 到 vw 的转换。 29 | 30 | - Use amfe-flexible? 31 | 32 | 当使用 rem 布局的时候,可以选择使用 [lib-flexible 2.x](https://github.com/amfe/lib-flexible) 来动态计算更新 rem 的值;当然也可以使用你自定义的 rem 计算方式,但是一定不能动态去需改 viewport,viewport width 只支持为 device-width 的情况 33 | 34 | > **使用rem/vw布局时**: 如果你的 remUnit 不能设置为 37.5,或者 viewportWidth 不是 375,可以使用 [postcss-design-convert](https://www.npmjs.com/package/postcss-design-convert) 插件完成相应转换。 35 | 36 | All cube-template special options. 37 | 38 | - Use post-compile? 39 | 40 | About post-compile https://didi.github.io/cube-ui/#/en-US/docs/post-compile 41 | 42 | - Import type 43 | 44 | Partly: https://didi.github.io/cube-ui/#/en-US/docs/quick-start#cube-Importondemand-anchor 45 | Fully: https://didi.github.io/cube-ui/#/en-US/docs/quick-start#cube-Fullyimport-anchor 46 | 47 | - Custom theme? 48 | 49 | https://didi.github.io/cube-ui/#/en-US/docs/theme 50 | 51 | - Use rem layout? 52 | 53 | Use rem to layout Page, if you want to change the basic rem unit value, then just modify the `remUnit` value in file `.postcssrc.js`. 54 | 55 | - Use vw layout? 56 | 57 | Use vw to layout Page, this use [postcss-px-to-viewport](https://github.com/evrone/postcss-px-to-viewport) plugin to process px to vw. 58 | 59 | - Use amfe-flexible? 60 | 61 | Use https://github.com/amfe/lib-flexible to set `rem` value 62 | -------------------------------------------------------------------------------- /meta.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | 4 | function sortObject(object) { 5 | // Based on https://github.com/yarnpkg/yarn/blob/v1.3.2/src/config.js#L79-L85 6 | const sortedObject = {}; 7 | Object.keys(object).sort().forEach(item => { 8 | sortedObject[item] = object[item]; 9 | }); 10 | return sortedObject; 11 | } 12 | 13 | module.exports = { 14 | "helpers": { 15 | "if_or": function (v1, v2, options) { 16 | if (v1 || v2) { 17 | return options.fn(this); 18 | } 19 | 20 | return options.inverse(this); 21 | } 22 | }, 23 | "prompts": { 24 | "name": { 25 | "type": "string", 26 | "required": true, 27 | "message": "Project name" 28 | }, 29 | "description": { 30 | "type": "string", 31 | "required": false, 32 | "message": "Project description", 33 | "default": "A Vue.js project" 34 | }, 35 | "author": { 36 | "type": "string", 37 | "message": "Author" 38 | }, 39 | "build": { 40 | "type": "list", 41 | "message": "Vue build", 42 | "choices": [ 43 | { 44 | "name": "Runtime + Compiler: recommended for most users", 45 | "value": "standalone", 46 | "short": "standalone" 47 | }, 48 | { 49 | "name": "Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere", 50 | "value": "runtime", 51 | "short": "runtime" 52 | } 53 | ] 54 | }, 55 | "postCompile": { 56 | "type": "confirm", 57 | "message": "Use post-compile?" 58 | }, 59 | "importType": { 60 | "type": "list", 61 | "message": "Import type", 62 | "choices": [ 63 | { 64 | "name": "partly, import component on demand, which makes the size of imported code lighter", 65 | "value": "partly", 66 | "short": "Partly" 67 | }, 68 | { 69 | "name": "fully, import all the components", 70 | "value": "fully", 71 | "short": "Fully" 72 | } 73 | ] 74 | }, 75 | "theme": { 76 | "when": "postCompile", 77 | "type": "confirm", 78 | "message": "Custom theme?" 79 | }, 80 | "rem": { 81 | "when": "postCompile", 82 | "type": "confirm", 83 | "message": "Use rem layout?", 84 | "default": false 85 | }, 86 | "amfeFlexible": { 87 | "when": "postCompile && rem", 88 | "type": "confirm", 89 | "message": "Use amfe-flexible?" 90 | }, 91 | "vw": { 92 | "when": "postCompile && !rem", 93 | "type": "confirm", 94 | "message": "Use vw layout?", 95 | "default": false 96 | }, 97 | "router": { 98 | "type": "confirm", 99 | "message": "Install vue-router?" 100 | }, 101 | "lint": { 102 | "type": "confirm", 103 | "message": "Use ESLint to lint your code?" 104 | }, 105 | "lintConfig": { 106 | "when": "lint", 107 | "type": "list", 108 | "message": "Pick an ESLint preset", 109 | "choices": [ 110 | { 111 | "name": "Standard (https://github.com/standard/standard)", 112 | "value": "standard", 113 | "short": "Standard" 114 | }, 115 | { 116 | "name": "Airbnb (https://github.com/airbnb/javascript)", 117 | "value": "airbnb", 118 | "short": "Airbnb" 119 | }, 120 | { 121 | "name": "none (configure it yourself)", 122 | "value": "none", 123 | "short": "none" 124 | } 125 | ] 126 | }, 127 | "unit": { 128 | "type": "confirm", 129 | "message": "Set up unit tests" 130 | }, 131 | "runner": { 132 | "when": "unit", 133 | "type": "list", 134 | "message": "Pick a test runner", 135 | "choices": [ 136 | { 137 | "name": "Jest", 138 | "value": "jest", 139 | "short": "jest" 140 | }, 141 | { 142 | "name": "Karma and Mocha", 143 | "value": "karma", 144 | "short": "karma" 145 | }, 146 | { 147 | "name": "none (configure it yourself)", 148 | "value": "noTest", 149 | "short": "noTest" 150 | } 151 | ] 152 | }, 153 | "e2e": { 154 | "type": "confirm", 155 | "message": "Setup e2e tests with Nightwatch?" 156 | } 157 | }, 158 | "filters": { 159 | ".eslintrc.js": "lint", 160 | ".eslintignore": "lint", 161 | "config/test.env.js": "unit || e2e", 162 | "build/webpack.test.conf.js": "unit && runner === 'karma'", 163 | "test/unit/**/*": "unit", 164 | "test/unit/index.js": "unit && runner === 'karma'", 165 | "test/unit/jest.conf.js": "unit && runner === 'jest'", 166 | "test/unit/karma.conf.js": "unit && runner === 'karma'", 167 | "test/unit/specs/index.js": "unit && runner === 'karma'", 168 | "test/unit/setup.js": "unit && runner === 'jest'", 169 | "test/e2e/**/*": "e2e", 170 | "src/router/**/*": "router", 171 | "src/theme.styl": "postCompile && theme" 172 | }, 173 | "complete": function (data) { 174 | const packageJsonFile = path.join( 175 | data.inPlace ? "" : data.destDirName, 176 | "package.json" 177 | ); 178 | const packageJson = JSON.parse(fs.readFileSync(packageJsonFile)); 179 | packageJson.devDependencies = sortObject(packageJson.devDependencies); 180 | packageJson.dependencies = sortObject(packageJson.dependencies); 181 | fs.writeFileSync( 182 | packageJsonFile, 183 | JSON.stringify(packageJson, null, 2) + "\n" 184 | ); 185 | 186 | const message = `To get started:\n\n ${data.inPlace ? '' : `cd ${data.destDirName}\n `}npm install\n npm run dev\n\nYeah,let's make an awesome app via cube-ui!`; 187 | console.log("\n" + message.split(/\r?\n/g).map(line => " " + line).join("\n")); 188 | } 189 | }; 190 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-cli-template-cube-ui", 3 | "version": "1.0.0", 4 | "license": "MIT", 5 | "description": "cube-ui template base on webpack for Vue-cli", 6 | "scripts": { 7 | "update": "node ./scripts/update-cube-version.js", 8 | "demo": "rm -rf demo && vue init ./ demo" 9 | }, 10 | "devDependencies": { 11 | "vue-cli": "^2.8.1" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/update-cube-version.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | const https = require('https') 4 | 5 | const options = { 6 | hostname: 'registry.npmjs.org', 7 | port: 443, 8 | path: '/cube-ui', 9 | method: 'GET' 10 | } 11 | 12 | // Get latest version of cube-ui 13 | const req = https.request(options, (res) => { 14 | if (res.statusCode !== 200) { 15 | console.error(`Request Failed. Status Code: ${statusCode}`) 16 | res.resume() 17 | 18 | return 19 | } 20 | 21 | let rawData = '' 22 | res.on('data', (data) => { 23 | rawData += data 24 | }) 25 | res.on('end', () => { 26 | const parsedData = JSON.parse(rawData) 27 | const version = parsedData['dist-tags'].latest 28 | replaceVersion(version) 29 | }) 30 | }) 31 | 32 | req.on('error', (e) => { 33 | console.error(e); 34 | }) 35 | 36 | req.end() 37 | 38 | function replaceVersion(version) { 39 | const packagePath = path.resolve(__dirname, '../template/package.json') 40 | let content = fs.readFileSync(packagePath).toString() 41 | content = content.replace(/(?<="cube-ui": "~)\d+\.\d+\.\d+(?=")/, version) 42 | fs.writeFileSync(packagePath, content) 43 | } 44 | -------------------------------------------------------------------------------- /template/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false 5 | }], 6 | "stage-2" 7 | ], 8 | "plugins": [ 9 | "transform-runtime" 10 | ]{{#if_or unit e2e}}, 11 | "env": { 12 | "test": { 13 | "presets": ["env", "stage-2"]{{#if_eq runner "karma"}}, 14 | "plugins": ["istanbul"]{{/if_eq}}{{#if_eq runner "jest"}}, 15 | "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]{{/if_eq}} 16 | } 17 | }{{/if_or}} 18 | } 19 | -------------------------------------------------------------------------------- /template/.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 | -------------------------------------------------------------------------------- /template/.eslintignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /config/ 3 | /dist/ 4 | /*.js 5 | {{#unit}} 6 | /test/unit/coverage/ 7 | {{/unit}} 8 | -------------------------------------------------------------------------------- /template/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | {{#if_eq lintConfig "standard"}} 13 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md 14 | extends: 'standard', 15 | {{/if_eq}} 16 | {{#if_eq lintConfig "airbnb"}} 17 | extends: 'airbnb-base', 18 | {{/if_eq}} 19 | // required to lint *.vue files 20 | plugins: [ 21 | 'html' 22 | ], 23 | {{#if_eq lintConfig "airbnb"}} 24 | // check if imports actually resolve 25 | settings: { 26 | 'import/resolver': { 27 | webpack: { 28 | config: 'build/webpack.base.conf.js' 29 | } 30 | } 31 | }, 32 | {{/if_eq}} 33 | // add your custom rules here 34 | rules: { 35 | {{#if_eq lintConfig "standard"}} 36 | // allow async-await 37 | 'generator-star-spacing': 'off', 38 | {{/if_eq}} 39 | {{#if_eq lintConfig "airbnb"}} 40 | // don't require .vue extension when importing 41 | 'import/extensions': ['error', 'always', { 42 | js: 'never', 43 | vue: 'never' 44 | }], 45 | // allow optionalDependencies 46 | 'import/no-extraneous-dependencies': ['error', { 47 | optionalDependencies: ['test/unit/index.js'] 48 | }], 49 | {{/if_eq}} 50 | // allow debugger during development 51 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /template/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | /dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | {{#unit}} 8 | /test/unit/coverage/ 9 | {{/unit}} 10 | {{#e2e}} 11 | /test/e2e/reports/ 12 | selenium-debug.log 13 | {{/e2e}} 14 | 15 | # Editor directories and files 16 | .idea 17 | .vscode 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | -------------------------------------------------------------------------------- /template/.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserslist" field in package.json 6 | "postcss-import": {}, 7 | "autoprefixer": {}{{#rem}}, 8 | "postcss-px2rem": { 9 | "remUnit": 37.5 10 | }{{/rem}}{{#vw}}, 11 | "postcss-px-to-viewport": { 12 | "viewportWidth": 375, 13 | "viewportHeight": 667, 14 | "unitPrecision": 5, 15 | "viewportUnit": "vw", 16 | "selectorBlackList": [], 17 | "minPixelValue": 1, 18 | "mediaQuery": false 19 | }{{/vw}} 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /template/README.md: -------------------------------------------------------------------------------- 1 | # {{ name }} 2 | 3 | > {{ description }} 4 | 5 | ## Build Setup 6 | 7 | ``` bash 8 | # install dependencies 9 | npm install 10 | 11 | # serve with hot reload at localhost:8080 12 | npm run dev 13 | 14 | # build for production with minification 15 | npm run build 16 | 17 | # build for production and view the bundle analyzer report 18 | npm run build --report 19 | {{#unit}} 20 | 21 | # run unit tests 22 | npm run unit 23 | {{/unit}} 24 | {{#e2e}} 25 | 26 | # run e2e tests 27 | npm run e2e 28 | {{/e2e}} 29 | {{#if_or unit e2e}} 30 | 31 | # run all tests 32 | npm test 33 | {{/if_or}} 34 | ``` 35 | 36 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 37 | -------------------------------------------------------------------------------- /template/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, 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 | -------------------------------------------------------------------------------- /template/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 | -------------------------------------------------------------------------------- /template/build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cube-ui/cube-template/2386c2c68e1f996b0f463a8abc2827b7a896670e/template/build/logo.png -------------------------------------------------------------------------------- /template/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 | {{#postCompile}} 58 | const stylusOptions = { 59 | 'resolve url': true{{#theme}}, 60 | 'import': [path.resolve(__dirname, '../src/theme')]{{/theme}} 61 | } 62 | {{/postCompile}} 63 | 64 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 65 | return { 66 | css: generateLoaders(), 67 | postcss: generateLoaders(), 68 | less: generateLoaders('less'), 69 | sass: generateLoaders('sass', { indentedSyntax: true }), 70 | scss: generateLoaders('sass'), 71 | stylus: generateLoaders('stylus'{{#postCompile}}, stylusOptions{{/postCompile}}), 72 | styl: generateLoaders('stylus'{{#postCompile}}, stylusOptions{{/postCompile}}) 73 | } 74 | } 75 | 76 | // Generate loaders for standalone style files (outside of .vue) 77 | exports.styleLoaders = function (options) { 78 | const output = [] 79 | const loaders = exports.cssLoaders(options) 80 | 81 | for (const extension in loaders) { 82 | const loader = loaders[extension] 83 | output.push({ 84 | test: new RegExp('\\.' + extension + '$'), 85 | use: loader 86 | }) 87 | } 88 | 89 | return output 90 | } 91 | 92 | exports.createNotifierCallback = () => { 93 | const notifier = require('node-notifier') 94 | 95 | return (severity, errors) => { 96 | if (severity !== 'error') return 97 | 98 | const error = errors[0] 99 | const filename = error.file && error.file.split('!').pop() 100 | 101 | notifier.notify({ 102 | title: packageConfig.name, 103 | message: severity + ': ' + error.name, 104 | subtitle: filename || '', 105 | icon: path.join(__dirname, 'logo.png') 106 | }) 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /template/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 | -------------------------------------------------------------------------------- /template/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 | const TransformModulesPlugin = require('webpack-transform-modules-plugin') 7 | {{#postCompile}} 8 | const PostCompilePlugin = require('webpack-post-compile-plugin') 9 | {{/postCompile}} 10 | 11 | function resolve (dir) { 12 | return path.join(__dirname, '..', dir) 13 | } 14 | 15 | const createLintingRule = () => ({ 16 | test: /\.(js|vue)$/, 17 | loader: 'eslint-loader', 18 | enforce: 'pre', 19 | include: [resolve('src'), resolve('test')], 20 | options: { 21 | formatter: require('eslint-friendly-formatter'), 22 | emitWarning: !config.dev.showEslintErrorsInOverlay 23 | } 24 | }) 25 | 26 | module.exports = { 27 | context: path.resolve(__dirname, '../'), 28 | entry: { 29 | app: './src/main.js' 30 | }, 31 | output: { 32 | path: config.build.assetsRoot, 33 | filename: '[name].js', 34 | publicPath: process.env.NODE_ENV === 'production' 35 | ? config.build.assetsPublicPath 36 | : config.dev.assetsPublicPath 37 | }, 38 | resolve: { 39 | extensions: ['.js', '.vue', '.json'], 40 | alias: { 41 | {{#if_eq build "standalone"}} 42 | 'vue$': 'vue/dist/vue.esm.js', 43 | {{/if_eq}} 44 | {{#unless postCompile}} 45 | 'cube-ui': 'cube-ui/lib', 46 | {{/unless}} 47 | '@': resolve('src'), 48 | } 49 | }, 50 | module: { 51 | rules: [ 52 | {{#lint}} 53 | ...(config.dev.useEslint ? [createLintingRule()] : []), 54 | {{/lint}} 55 | { 56 | test: /\.vue$/, 57 | loader: 'vue-loader', 58 | options: vueLoaderConfig 59 | }, 60 | { 61 | test: /\.js$/, 62 | loader: 'babel-loader', 63 | include: [resolve('src'), resolve('test')] 64 | }, 65 | { 66 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 67 | loader: 'url-loader', 68 | options: { 69 | limit: 10000, 70 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 71 | } 72 | }, 73 | { 74 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 75 | loader: 'url-loader', 76 | options: { 77 | limit: 10000, 78 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 79 | } 80 | }, 81 | { 82 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 83 | loader: 'url-loader', 84 | options: { 85 | limit: 10000, 86 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 87 | } 88 | } 89 | ] 90 | }, 91 | node: { 92 | // prevent webpack from injecting useless setImmediate polyfill because Vue 93 | // source contains it (although only uses it if it's native). 94 | setImmediate: false, 95 | // prevent webpack from injecting mocks to Node native modules 96 | // that does not make sense for the client 97 | dgram: 'empty', 98 | fs: 'empty', 99 | net: 'empty', 100 | tls: 'empty', 101 | child_process: 'empty' 102 | }, 103 | plugins: [ 104 | {{#postCompile}}new PostCompilePlugin(), 105 | {{/postCompile}}new TransformModulesPlugin() 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /template/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 baseWebpackConfig = require('./webpack.base.conf') 7 | const HtmlWebpackPlugin = require('html-webpack-plugin') 8 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 9 | const portfinder = require('portfinder') 10 | 11 | const HOST = process.env.HOST 12 | const PORT = process.env.PORT && Number(process.env.PORT) 13 | 14 | const devWebpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: config.dev.devtool, 20 | 21 | // these devServer options should be customized in /config/index.js 22 | devServer: { 23 | clientLogLevel: 'warning', 24 | historyApiFallback: true, 25 | hot: true, 26 | compress: true, 27 | host: HOST || config.dev.host, 28 | port: PORT || config.dev.port, 29 | open: config.dev.autoOpenBrowser, 30 | overlay: config.dev.errorOverlay 31 | ? { warnings: false, errors: true } 32 | : false, 33 | publicPath: config.dev.assetsPublicPath, 34 | proxy: config.dev.proxyTable, 35 | quiet: true, // necessary for FriendlyErrorsPlugin 36 | watchOptions: { 37 | poll: config.dev.poll, 38 | } 39 | }, 40 | plugins: [ 41 | new webpack.DefinePlugin({ 42 | 'process.env': require('../config/dev.env') 43 | }), 44 | new webpack.HotModuleReplacementPlugin(), 45 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 46 | new webpack.NoEmitOnErrorsPlugin(), 47 | // https://github.com/ampedandwired/html-webpack-plugin 48 | new HtmlWebpackPlugin({ 49 | filename: 'index.html', 50 | template: 'index.html', 51 | inject: true 52 | }), 53 | ] 54 | }) 55 | 56 | module.exports = new Promise((resolve, reject) => { 57 | portfinder.basePort = process.env.PORT || config.dev.port 58 | portfinder.getPort((err, port) => { 59 | if (err) { 60 | reject(err) 61 | } else { 62 | // publish the new Port, necessary for e2e tests 63 | process.env.PORT = port 64 | // add port to devServer config 65 | devWebpackConfig.devServer.port = port 66 | 67 | // Add FriendlyErrorsPlugin 68 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 69 | compilationSuccessInfo: { 70 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 71 | }, 72 | onErrors: config.dev.notifyOnErrors 73 | ? utils.createNotifierCallback() 74 | : undefined 75 | })) 76 | 77 | resolve(devWebpackConfig) 78 | } 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /template/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 = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing' 15 | ? require('../config/test.env') 16 | : {{/if_or}}require('../config/prod.env') 17 | 18 | const webpackConfig = merge(baseWebpackConfig, { 19 | module: { 20 | rules: utils.styleLoaders({ 21 | sourceMap: config.build.productionSourceMap, 22 | extract: true, 23 | usePostCSS: true 24 | }) 25 | }, 26 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 30 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 31 | }, 32 | plugins: [ 33 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 34 | new webpack.DefinePlugin({ 35 | 'process.env': env 36 | }), 37 | new UglifyJsPlugin({ 38 | uglifyOptions: { 39 | compress: { 40 | warnings: false 41 | } 42 | }, 43 | sourceMap: config.build.productionSourceMap, 44 | parallel: true 45 | }), 46 | // extract css into its own file 47 | new ExtractTextPlugin({ 48 | filename: utils.assetsPath('css/[name].[contenthash].css'), 49 | // set the following option to `true` if you want to extract CSS from 50 | // codesplit chunks into this main css file as well. 51 | // This will result in *all* of your app's CSS being loaded upfront. 52 | allChunks: false, 53 | }), 54 | // Compress extracted CSS. We are using this plugin so that possible 55 | // duplicated CSS from different components can be deduped. 56 | new OptimizeCSSPlugin({ 57 | cssProcessorOptions: config.build.productionSourceMap 58 | ? { safe: true, map: { inline: false } } 59 | : { safe: true } 60 | }), 61 | // generate dist index.html with correct asset hash for caching. 62 | // you can customize output by editing /index.html 63 | // see https://github.com/ampedandwired/html-webpack-plugin 64 | new HtmlWebpackPlugin({ 65 | filename: {{#if_or unit e2e}}process.env.NODE_ENV === 'testing' 66 | ? 'index.html' 67 | : {{/if_or}}config.build.index, 68 | template: 'index.html', 69 | inject: true, 70 | minify: { 71 | removeComments: true, 72 | collapseWhitespace: true, 73 | removeAttributeQuotes: true 74 | // more options: 75 | // https://github.com/kangax/html-minifier#options-quick-reference 76 | }, 77 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 78 | chunksSortMode: 'dependency' 79 | }), 80 | // keep module.id stable when vender modules does not change 81 | new webpack.HashedModuleIdsPlugin(), 82 | // enable scope hoisting 83 | new webpack.optimize.ModuleConcatenationPlugin(), 84 | // split vendor js into its own file 85 | new webpack.optimize.CommonsChunkPlugin({ 86 | name: 'vendor', 87 | minChunks (module) { 88 | // any required modules inside node_modules are extracted to vendor 89 | return ( 90 | module.resource && 91 | /\.js$/.test(module.resource) && 92 | module.resource.indexOf( 93 | path.join(__dirname, '../node_modules') 94 | ) === 0 95 | ) 96 | } 97 | }), 98 | // extract webpack runtime and module manifest to its own file in order to 99 | // prevent vendor hash from being updated whenever app bundle is updated 100 | new webpack.optimize.CommonsChunkPlugin({ 101 | name: 'manifest', 102 | minChunks: Infinity 103 | }), 104 | // This instance extracts shared chunks from code splitted chunks and bundles them 105 | // in a separate chunk, similar to the vendor chunk 106 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 107 | new webpack.optimize.CommonsChunkPlugin({ 108 | name: 'app', 109 | async: 'vendor-async', 110 | children: true, 111 | minChunks: 3 112 | }), 113 | 114 | // copy custom static assets 115 | new CopyWebpackPlugin([ 116 | { 117 | from: path.resolve(__dirname, '../static'), 118 | to: config.build.assetsSubDirectory, 119 | ignore: ['.*'] 120 | } 121 | ]) 122 | ] 123 | }) 124 | 125 | if (config.build.productionGzip) { 126 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 127 | 128 | webpackConfig.plugins.push( 129 | new CompressionWebpackPlugin({ 130 | asset: '[path].gz[query]', 131 | algorithm: 'gzip', 132 | test: new RegExp( 133 | '\\.(' + 134 | config.build.productionGzipExtensions.join('|') + 135 | ')$' 136 | ), 137 | threshold: 10240, 138 | minRatio: 0.8 139 | }) 140 | ) 141 | } 142 | 143 | if (config.build.bundleAnalyzerReport) { 144 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 145 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 146 | } 147 | 148 | module.exports = webpackConfig 149 | -------------------------------------------------------------------------------- /template/build/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // This is the webpack config used for unit tests. 3 | 4 | const utils = require('./utils') 5 | const webpack = require('webpack') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | 9 | const webpackConfig = merge(baseWebpackConfig, { 10 | // use inline sourcemap for karma-sourcemap-loader 11 | module: { 12 | rules: utils.styleLoaders() 13 | }, 14 | devtool: '#inline-source-map', 15 | resolveLoader: { 16 | alias: { 17 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 18 | // see discussion at https://github.com/vuejs/vue-loader/issues/724 19 | 'scss-loader': 'sass-loader' 20 | } 21 | }, 22 | plugins: [ 23 | new webpack.DefinePlugin({ 24 | 'process.env': require('../config/test.env') 25 | }) 26 | ] 27 | }) 28 | 29 | // no need for app entry during tests 30 | delete webpackConfig.entry 31 | 32 | module.exports = webpackConfig 33 | -------------------------------------------------------------------------------- /template/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 | -------------------------------------------------------------------------------- /template/config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.2.5 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: '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 | // CSS Sourcemaps off by default because relative paths are "buggy" 44 | // with this option, according to the CSS-Loader README 45 | // (https://github.com/webpack/css-loader#sourcemaps) 46 | // In our experience, they generally work as expected, 47 | // just be aware of this issue when enabling this option. 48 | cssSourceMap: false, 49 | }, 50 | 51 | build: { 52 | // Template for index.html 53 | index: path.resolve(__dirname, '../dist/index.html'), 54 | 55 | // Paths 56 | assetsRoot: path.resolve(__dirname, '../dist'), 57 | assetsSubDirectory: 'static', 58 | assetsPublicPath: '/', 59 | 60 | /** 61 | * Source Maps 62 | */ 63 | 64 | productionSourceMap: true, 65 | // https://webpack.js.org/configuration/devtool/#production 66 | devtool: '#source-map', 67 | 68 | // Gzip off by default as many popular static hosts such as 69 | // Surge or Netlify already gzip all static assets for you. 70 | // Before setting to `true`, make sure to: 71 | // npm install --save-dev compression-webpack-plugin 72 | productionGzip: false, 73 | productionGzipExtensions: ['js', 'css'], 74 | 75 | // Run the build command with an extra argument to 76 | // View the bundle analyzer report after build finishes: 77 | // `npm run build --report` 78 | // Set to `true` or `false` to always turn it on or off 79 | bundleAnalyzerReport: process.env.npm_config_report 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /template/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /template/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 | -------------------------------------------------------------------------------- /template/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |