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

初始化自定义仓库 #1495

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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).
2 changes: 1 addition & 1 deletion template/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false, // if you are using ts-loader, setting this to true will make typescript errors show up during build
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
chunks: false,
chunkModules: false
}) + '\n\n')
Expand Down
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
32 changes: 0 additions & 32 deletions template/build/webpack.test.conf.js

This file was deleted.

Loading