Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #1496

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Master #1496

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const path = require('path')

module.exports = {
dev: {
/ Paths
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
Expand Down
8 changes: 4 additions & 4 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ So, the environment variables are:

As we can see, `test.env` inherits the `dev.env` and the `dev.env` inherits the `prod.env`.

### Usage
### Usage

It is simple to use the environment variables in your code. For example:
It is simple to use the environment variables in your code. For example:

```js
Vue.config.productionTip = process.env.NODE_ENV === 'production'
```js
Vue.config.productionTip = process.env.NODE_ENV === 'production'
```
3 changes: 2 additions & 1 deletion docs/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ You can run the following command to let eslint fix any errors it finds (if it c
npm run lint -- --fix
```

*(The `--` in the middle is necessary to ensure the `--fix` option is passdd to `eslint`, not to `npm`. It can be omitted whne using yarn)*
*(The `--` in the middle is necessary to ensure the `--fix` option is passed to `eslint`, not to `npm`. It can be omitted when using yarn)*


8 changes: 4 additions & 4 deletions docs/pre-processors.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pre-Processors

This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, SASS, Stylus, and PostCSS. To use a pre-processor, all you need to do is install the appropriate webpack loader for it. For example, to use SASS:
This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, Sass, Stylus, and PostCSS. To use a pre-processor, all you need to do is install the appropriate webpack loader for it. For example, to use Sass:

``` bash
npm install sass-loader node-sass --save-dev
Expand All @@ -14,11 +14,11 @@ Once installed, you can use the pre-processors inside your `*.vue` components us

``` html
<style lang="scss">
/* write SASS! */
/* write Sass! */
</style>
```

### A note on SASS syntax
### A note on Sass syntax

- `lang="scss"` corresponds to the CSS-superset syntax (with curly braces and semicolons).
- `lang="sass"` corresponds to the indentation-based syntax.
Expand All @@ -27,7 +27,7 @@ Once installed, you can use the pre-processors inside your `*.vue` components us

Styles in `*.vue` files and style files (`*.css`, `*.scss` etc) are piped through PostCSS by default, so you don't need to use a specific loader for it.

You can simply add PostCSS plugins you want to use to the `.postcssrc.js`file in your project's root directory:
You can simply add PostCSS plugins you want to use to the `.postcssrc.js` file in your project's root directory:

``` js
// https://github.com/michael-ciniawsky/postcss-load-config
Expand Down
4 changes: 2 additions & 2 deletions docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
│ │ ├── eslintrc # config file for eslint with extra settings only for unit tests
│ │ ├── index.js # test build entry file
│ │ ├── jest.conf.js # Config file when using Jest for unit tests
│ │ ── karma.conf.js # test runner config file when using Karma for unit tests
│ │ ── setup.js # file that runs before Jest runs your unit tests
│ │ ── karma.conf.js # test runner config file when using Karma for unit tests
│ │ ── setup.js # file that runs before Jest runs your unit tests
│ └── e2e/ # e2e tests
│ │   ├── specs/ # test spec files
│ │   ├── custom-assertions/ # custom assertions for e2e tests
Expand Down
6 changes: 3 additions & 3 deletions scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ With the code from `index.js`, we insert those answers into the metalsmith metad

## The scenarios

We currently have 3 scenrios set up:
We currently have 3 scenarios set up:

1. 'minimal': it basically answers "no" to ever choice, so no router, no elint, no tests
1. 'minimal': it basically answers "no" to ever choice, so no router, no eslint, no tests
2. 'full': It answers "yes" to every choice. With router, with linting (standard), with full tests (jest & e2e)
3. 'full-airbnb-karma': like 'full', but using airbnb eslint config instead od standard and karma instead of jest for unnit tests.
3. 'full-airbnb-karma': like 'full', but using airbnb eslint config instead of standard and karma instead of jest for unit tests.

Other permutations might be worth testing to secure against edge cases, but this gives us a decent level of security over common combinations.

Expand Down
9 changes: 4 additions & 5 deletions template/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
}],
"stage-2"
],
"plugins": ["transform-vue-jsx", "transform-runtime"]{{#if_or unit e2e}},
"plugins": ["transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"]{{#if_eq runner "karma"}},
"plugins": ["transform-vue-jsx", "istanbul"]{{/if_eq}}{{#if_eq runner "jest"}},
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]{{/if_eq}}
"presets": ["env", "stage-2"],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
}
}{{/if_or}}
}
}
3 changes: 1 addition & 2 deletions template/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
/config/
/dist/
/*.js
{{#unit}}
/test/unit/coverage/
{{/unit}}
/src/util/
56 changes: 9 additions & 47 deletions template/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,29 @@ module.exports = {
env: {
browser: true,
},
{{#if_eq lintConfig "standard"}}
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
{{/if_eq}}
{{#if_eq lintConfig "airbnb"}}
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
extends: ['plugin:vue/essential', 'airbnb-base'],
{{/if_eq}}
{{#if_eq lintConfig "none"}}
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
extends: ['plugin:vue/essential'],
{{/if_eq}}
// required to lint *.vue files
plugins: [
'vue'
],
{{#if_eq lintConfig "airbnb"}}
// check if imports actually resolve
settings: {
'import/resolver': {
webpack: {
config: 'build/webpack.base.conf.js'
}
}
},
{{/if_eq}}
// add your custom rules here
rules: {
{{#if_eq lintConfig "standard"}}
// 0 禁用此规则 1 不符合规则即给出警告 2 不符合规则即报错
// allow async-await
'generator-star-spacing': 'off',
{{/if_eq}}
{{#if_eq lintConfig "airbnb"}}
// don't require .vue extension when importing
'import/extensions': ['error', 'always', {
js: 'never',
vue: 'never'
}],
// disallow reassignment of function parameters
// disallow parameter object manipulation except for specific exclusions
'no-param-reassign': ['error', {
props: true,
ignorePropertyModificationsFor: [
'state', // for vuex state
'acc', // for reduce accumulators
'e' // for e.returnvalue
]
}],
// allow optionalDependencies
'import/no-extraneous-dependencies': ['error', {
optionalDependencies: ['test/unit/index.js']
}],
{{/if_eq}}
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
"no-unused-vars": [0, { "vars": "all", "args": "after-used" }],//不能有声明后未被使用的变量或参数
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
"semi": [2, "always"],//语句强制分号结尾
"semi-spacing": process.env.NODE_ENV === 'production' ? 'off' : [1, { "before": false, "after": true }],//分号前后空格
"space-before-function-paren": [0, "always"],//函数定义时括号前面要不要有空格
"no-redeclare": 0,// 允许重复声明变量
"no-eval": 0//允许使用eval
}
}
6 changes: 1 addition & 5 deletions template/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
{{#unit}}
/test/unit/coverage/
{{/unit}}
{{#e2e}}
/test/e2e/reports/
selenium-debug.log
{{/e2e}}

/src/components/
# Editor directories and files
.idea
.vscode
Expand Down
10 changes: 2 additions & 8 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# {{ name }}
# hello2

> {{ description }}
> A Vue.js project

## Build Setup

Expand All @@ -16,21 +16,15 @@ npm run build

# build for production and view the bundle analyzer report
npm run build --report
{{#unit}}

# run unit tests
npm run unit
{{/unit}}
{{#e2e}}

# run e2e tests
npm run e2e
{{/e2e}}
{{#if_or unit e2e}}

# run all tests
npm test
{{/if_or}}
```

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).
68 changes: 58 additions & 10 deletions template/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@ exports.cssLoaders = function (options) {
const cssLoader = {
loader: 'css-loader',
options: {
sourceMap: options.sourceMap
}
}

const postcssLoader = {
loader: 'postcss-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}

// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]

function generateLoaders(loader, loaderOptions) {
var loaders = [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
Expand Down Expand Up @@ -99,3 +92,58 @@ exports.createNotifierCallback = () => {
})
}
}

/**新增加多页面入口*/
// glob是webpack安装时依赖的一个第三方模块,还模块允许你使用 *等符号, 例如lib/*.js就是获取lib文件夹下的所有js后缀名的文件
var glob = require('glob')
// 页面模板
var HtmlWebpackPlugin = require('html-webpack-plugin')
// 取得相应的页面路径,因为之前的配置,所以是src文件夹下的pages文件夹
var PAGE_PATH = path.resolve(__dirname, '../src/pages')
// 用于做相应的merge处理
var merge = require('webpack-merge')


//多入口配置
// 通过glob模块读取pages文件夹下的所有对应文件夹下的js后缀文件,如果该文件存在
// 那么就作为入口处理
exports.entries = function () {
var entryFiles = glob.sync(PAGE_PATH + '/*/*.js')
var map = {}
entryFiles.forEach((filePath) => {
var filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
map[filename] = filePath
})
return map
}

//多页面输出配置
// 与上面的多页面入口配置相同,读取pages文件夹下的对应的html后缀文件,然后放入数组中
exports.htmlPlugin = function () {
let entryHtml = glob.sync(PAGE_PATH + '/*/*.html')
let arr = []
entryHtml.forEach((filePath) => {
let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
let conf = {
// 模板来源
template: filePath,
// 文件名称
filename: filename + '.html',
// 页面模板需要加对应的js脚本,如果不加这行则每个页面都会引入所有的js脚本
chunks: ['manifest', 'vendor', filename],
inject: true
}
if (process.env.NODE_ENV === 'production') {
conf = merge(conf, {
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency'
})
}
arr.push(new HtmlWebpackPlugin(conf))
})
return arr
}
16 changes: 8 additions & 8 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function resolve (dir) {
return path.join(__dirname, '..', dir)
}

{{#lint}}const createLintingRule = () => ({
const createLintingRule = () => ({
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
Expand All @@ -17,12 +17,16 @@ function resolve (dir) {
formatter: require('eslint-friendly-formatter'),
emitWarning: !config.dev.showEslintErrorsInOverlay
}
}){{/lint}}
})

module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
// entry: {
// app: './src/main.js'
// },
entry: utils.entries(),
externals: {
// "BMap": "BMap"
},
output: {
path: config.build.assetsRoot,
Expand All @@ -34,17 +38,13 @@ module.exports = {
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
{{#if_eq build "standalone"}}
'vue$': 'vue/dist/vue.esm.js',
{{/if_eq}}
'@': resolve('src'),
}
},
module: {
rules: [
{{#lint}}
...(config.dev.useEslint ? [createLintingRule()] : []),
{{/lint}}
{
test: /\.vue$/,
loader: 'vue-loader',
Expand Down
8 changes: 4 additions & 4 deletions template/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

const env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
const env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: {{/if_or}}require('../config/prod.env')
: require('../config/prod.env')

const webpackConfig = merge(baseWebpackConfig, {
module: {
Expand Down Expand Up @@ -63,9 +63,9 @@ const webpackConfig = merge(baseWebpackConfig, {
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: {{/if_or}}config.build.index,
: config.build.index,
template: 'index.html',
inject: true,
minify: {
Expand Down
Loading