Skip to content

Commit b97993f

Browse files
committed
📙 add eslint
1 parent 7971001 commit b97993f

File tree

3 files changed

+60
-63
lines changed

3 files changed

+60
-63
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
'extends': 'vue',
3+
'env': {
4+
'browser': true,
5+
'node': true
6+
}
7+
};

package.json

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@
88
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
99
},
1010
"dependencies": {
11-
"element-ui": "^1.1.6",
12-
"vue": "^2.1.10"
11+
"element-ui": "^1.2.3",
12+
"vue": "^2.2.1"
1313
},
1414
"devDependencies": {
15-
"babel-core": "^6.22.1",
16-
"babel-loader": "^6.2.10",
15+
"babel-core": "^6.23.1",
16+
"babel-loader": "^6.3.2",
1717
"babel-preset-es2015": "^6.22.0",
18-
"cross-env": "^3.1.4",
19-
"css-loader": "^0.26.1",
20-
"extract-text-webpack-plugin": "^2.0.0-rc.2",
21-
"file-loader": "^0.10.0",
18+
"cross-env": "^3.2.3",
19+
"css-loader": "^0.26.2",
20+
"extract-text-webpack-plugin": "^2.1.0",
21+
"file-loader": "^0.10.1",
2222
"glob": "^7.1.1",
23-
"html-loader": "^0.4.4",
23+
"html-loader": "^0.4.5",
2424
"html-webpack-plugin": "^2.28.0",
25-
"style-loader": "^0.13.1",
26-
"url-loader": "^0.5.7",
27-
"vue-loader": "^10.3.0",
28-
"vue-template-compiler": "^2.1.10",
25+
"style-loader": "^0.13.2",
26+
"url-loader": "^0.5.8",
27+
"vue-loader": "^11.1.4",
28+
"vue-template-compiler": "^2.2.1",
2929
"webpack": "^2.2.1",
30-
"webpack-dev-server": "^2.3.0"
30+
"webpack-dev-server": "^2.4.1",
31+
"eslint": "^3.17.0",
32+
"eslint-config-vue": "^2.0.2",
33+
"eslint-plugin-vue": "^2.0.1"
3134
}
3235
}

webpack.config.js

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
const { join, resolve } = require('path');
2-
const webpack = require('webpack');
3-
const glob = require('glob');
1+
const { join, resolve } = require('path')
2+
const webpack = require('webpack')
3+
const glob = require('glob')
44

5-
const HtmlWebpackPlugin = require('html-webpack-plugin');
6-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
7-
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
5+
const HtmlWebpackPlugin = require('html-webpack-plugin')
6+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
7+
const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
88

9-
let entries = {};
10-
let chunks = [];
11-
getEntriesAndChunks();
9+
const entries = {}
10+
const chunks = []
11+
glob.sync('./src/pages/**/*.js').forEach(function (name) {
12+
const n = name.slice(name.lastIndexOf('src/') + 10, name.length - 3)
13+
entries[n] = [name]
14+
chunks.push(n)
15+
})
1216

13-
let config = {
17+
const config = {
1418
entry: entries,
1519
output: {
1620
path: resolve(__dirname, './dist'),
1721
filename: '[name].js',
1822
publicPath: '/'
1923
},
2024
resolve: {
21-
//配置别名,在项目中可缩减引用路径
25+
// 配置别名,在项目中可缩减引用路径
2226
extensions: ['.js', '.vue'],
2327
alias: {
24-
assets: join(__dirname,'/src/assets'),
25-
components: join(__dirname,'/src/components'),
28+
assets: join(__dirname, '/src/assets'),
29+
components: join(__dirname, '/src/components'),
2630
root: join(__dirname, 'node_modules')
2731
}
2832
},
@@ -87,53 +91,36 @@ let config = {
8791
'/api': {
8892
target: 'http://127.0.0.1:8080',
8993
changeOrigin: true,
90-
pathRewrite: {'^/api' : ''}
94+
pathRewrite: { '^/api': '' }
9195
}
92-
},
96+
}
9397
},
9498
devtool: '#eval-source-map'
95-
};
99+
}
96100

97-
const pages = getHtmls();
98-
pages.forEach(function (pathname) {
101+
glob.sync('./src/pages/**/*.html').forEach(function (name) {
102+
const pathname = name.slice(name.lastIndexOf('src/') + 4, name.length - 5)
99103
// filename 用文件夹名字
100-
var conf = {
101-
filename: pathname.substring(6, pathname.length - 4) + '.html', //生成的html存放路径,相对于path
102-
template: 'src/' + pathname + '.html', //html模板路径
103-
};
104-
var chunk = pathname.substring(6, pathname.length);
104+
const conf = {
105+
filename: pathname.substring(6, pathname.length - 4) + '.html', // 生成的html存放路径,相对于path
106+
template: 'src/' + pathname + '.html' // html模板路径
107+
}
108+
const chunk = pathname.substring(6, pathname.length)
105109
if (chunks.indexOf(chunk) > -1) {
106-
conf.inject = 'body';
107-
conf.chunks = ['vendors', chunk];
110+
conf.inject = 'body'
111+
conf.chunks = ['vendors', chunk]
108112
}
109113
if (process.env.NODE_ENV === 'production') {
110-
conf.hash = true;
114+
conf.hash = true
111115
}
112-
conf.favicon = './src/assets/img/logo.png';
113-
config.plugins.push(new HtmlWebpackPlugin(conf));
114-
});
115-
116-
module.exports = config;
116+
conf.favicon = './src/assets/img/logo.png'
117+
config.plugins.push(new HtmlWebpackPlugin(conf))
118+
})
117119

118-
function getEntriesAndChunks() {
119-
glob.sync('./src/pages/**/*.js').forEach(function (name) {
120-
var n = name.slice(name.lastIndexOf('src/') + 10, name.length -3);
121-
entries[n] = [name];
122-
chunks.push(n);
123-
});
124-
}
125-
126-
function getHtmls() {
127-
var htmls = [];
128-
glob.sync('./src/pages/**/*.html').forEach(function (name) {
129-
var n = name.slice(name.lastIndexOf('src/') + 4, name.length - 5);
130-
htmls.push(n);
131-
});
132-
return htmls;
133-
}
120+
module.exports = config
134121

135122
if (process.env.NODE_ENV === 'production') {
136-
module.exports.devtool = '#source-map';
123+
module.exports.devtool = '#source-map'
137124
// http://vue-loader.vuejs.org/en/workflow/production.html
138125
module.exports.plugins = (module.exports.plugins || []).concat([
139126
new webpack.DefinePlugin({
@@ -146,5 +133,5 @@ if (process.env.NODE_ENV === 'production') {
146133
warnings: false
147134
}
148135
})
149-
]);
136+
])
150137
}

0 commit comments

Comments
 (0)