Skip to content

Commit 1b78926

Browse files
committed
workflow(init): use hashrouter
1 parent 24a6f39 commit 1b78926

31 files changed

+475
-409
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
[
77
"@babel/preset-react"
88
]
9-
]
9+
],
10+
"plugins": ["@babel/plugin-proposal-class-properties"]
1011
}

.eslintrc

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"parser": "babel-eslint",
23
"plugins": [
34
"react",
45
"prettier"
@@ -13,5 +14,12 @@
1314
"legacyDecorators": true,
1415
"jsx": true
1516
}
17+
},
18+
"env": {
19+
"browser": true,
20+
"node": true
21+
},
22+
"rules": {
23+
"no-console": "off"
1624
}
1725
}

.prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/*.md
2+
**/*.svg
3+
**/*.ejs
4+
**/*.html
5+
package.json

.prettierrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"printWidth": 100,
5+
"overrides": [
6+
{
7+
"files": ".prettierrc",
8+
"options": { "parser": "json" }
9+
}
10+
]
11+
}

build/webpack.analyzer.conf.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const prodConfig = require('./webpack.prod.conf');
22
const merge = require('webpack-merge');
33
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
44
module.exports = merge(prodConfig, {
5-
plugins: [
6-
//分析依赖
7-
new BundleAnalyzerPlugin()
8-
]
9-
});
5+
plugins: [
6+
//分析依赖
7+
new BundleAnalyzerPlugin(),
8+
],
9+
});

build/webpack.base.conf.js

+90-86
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,102 @@
11
const path = require('path');
2-
const webpack = require("webpack");
3-
const glob = require("glob");
4-
const fs = require('fs')
2+
const webpack = require('webpack');
3+
const glob = require('glob');
4+
const fs = require('fs');
55

66
// require("./env-config");
7-
const projectConfig = require('../config/projectConfig')
7+
const projectConfig = require('../config/projectConfig');
88
const isDev = process.env.NODE_ENV == 'development';
99

1010
//消除冗余的css
11-
const purifyCssWebpack = require("purifycss-webpack");
11+
const purifyCssWebpack = require('purifycss-webpack');
1212
// html模板
13-
const htmlWebpackPlugin = require("html-webpack-plugin");
13+
const htmlWebpackPlugin = require('html-webpack-plugin');
1414
//静态资源输出
15-
const copyWebpackPlugin = require("copy-webpack-plugin");
16-
const rules = require("./webpack.rules.conf.js");
15+
const copyWebpackPlugin = require('copy-webpack-plugin');
16+
const rules = require('./webpack.rules.conf.js');
1717

18-
const getTemplate = function () {
19-
let pathTemp = `${projectConfig.localPath}/document.html`;
20-
if(!fs.existsSync(pathTemp)){
21-
pathTemp = path.resolve(projectConfig.localPath, '../', './document.html')
22-
}
23-
return pathTemp
24-
}
18+
const getTemplate = function() {
19+
let pathTemp = `${projectConfig.localPath}/document.html`;
20+
if (!fs.existsSync(pathTemp)) {
21+
pathTemp = path.resolve(projectConfig.localPath, '../', './document.html');
22+
}
23+
return pathTemp;
24+
};
2525

2626
module.exports = {
27-
entry: {
28-
app: projectConfig.localPath + 'index.js'
29-
},
30-
output: {
31-
path: path.resolve(__dirname, '../dist'),
32-
filename: isDev ? './js/[name].js':'./js/[name].[hash].js',
33-
publicPath: isDev ? '/':'./'
34-
},
35-
module: {
36-
rules: [...rules]
37-
},
38-
resolve: {
39-
alias: {
40-
'@': path.resolve(__dirname, '../src')
41-
}
42-
},
43-
//将外部变量或者模块加载进来
44-
externals: {
45-
// 'jquery': 'window.jQuery'
46-
},
47-
// 提取公共代码
48-
optimization: {
49-
splitChunks: {
50-
cacheGroups: {
51-
vendor: { // 抽离第三方插件
52-
test: /node_modules/, // 指定是node_modules下的第三方包
53-
chunks: 'initial',
54-
name: 'vendor', // 打包后的文件名,任意命名
55-
// 设置优先级,防止和自定义的公共代码提取时被覆盖,不进行打包
56-
priority: 10
57-
},
58-
utils: { // 抽离自己写的公共代码,common这个名字可以随意起
59-
chunks: 'initial',
60-
name: 'common', // 任意命名
61-
minSize: 0, // 只要超出0字节就生成一个新包
62-
minChunks: 2
63-
}
64-
}
65-
}
27+
entry: {
28+
app: projectConfig.localPath + 'index.js',
29+
},
30+
output: {
31+
path: path.resolve(__dirname, '../dist'),
32+
filename: isDev ? './js/[name].js' : './js/[name].[hash].js',
33+
publicPath: isDev ? '/' : './',
34+
},
35+
module: {
36+
rules: [...rules],
37+
},
38+
resolve: {
39+
alias: {
40+
'@': path.resolve(__dirname, '../src'),
6641
},
67-
plugins: [
68-
// 全局暴露统一入口
69-
new webpack.ProvidePlugin({
70-
71-
}),
72-
//静态资源输出
73-
new copyWebpackPlugin([{
74-
from: path.resolve(__dirname, "../src/assets"),
75-
to: './assets',
76-
ignore: ['.*']
77-
}]),
78-
// 消除冗余的css代码
79-
new purifyCssWebpack({
80-
paths: glob.sync(path.join(__dirname, "../src/*.html"))
81-
}),
82-
new htmlWebpackPlugin({
83-
template: getTemplate(),
84-
filename: `index.html`,
85-
// favicon: './favicon.ico',
86-
// title: title,
87-
inject: true,
88-
hash: true, //开启hash ?[hash]
89-
// chunks: chunks,
90-
minify: isDev ? false : {
91-
removeComments: true, //移除HTML中的注释
92-
collapseWhitespace: true, //折叠空白区域 也就是压缩代码
93-
removeAttributeQuotes: true, //去除属性引用
94-
},
95-
}),
96-
new webpack.optimize.ModuleConcatenationPlugin()
97-
]
98-
}
42+
},
43+
//将外部变量或者模块加载进来
44+
externals: {
45+
// 'jquery': 'window.jQuery'
46+
},
47+
// 提取公共代码
48+
optimization: {
49+
splitChunks: {
50+
cacheGroups: {
51+
vendor: {
52+
// 抽离第三方插件
53+
test: /node_modules/, // 指定是node_modules下的第三方包
54+
chunks: 'initial',
55+
name: 'vendor', // 打包后的文件名,任意命名
56+
// 设置优先级,防止和自定义的公共代码提取时被覆盖,不进行打包
57+
priority: 10,
58+
},
59+
utils: {
60+
// 抽离自己写的公共代码,common这个名字可以随意起
61+
chunks: 'initial',
62+
name: 'common', // 任意命名
63+
minSize: 0, // 只要超出0字节就生成一个新包
64+
minChunks: 2,
65+
},
66+
},
67+
},
68+
},
69+
plugins: [
70+
// 全局暴露统一入口
71+
new webpack.ProvidePlugin({}),
72+
//静态资源输出
73+
new copyWebpackPlugin([
74+
// {
75+
// from: path.resolve(__dirname, "../src/assets"),
76+
// to: "./assets",
77+
// ignore: [".*"]
78+
// }
79+
]),
80+
// 消除冗余的css代码
81+
new purifyCssWebpack({
82+
paths: glob.sync(path.join(__dirname, '../src/*.html')),
83+
}),
84+
new htmlWebpackPlugin({
85+
template: getTemplate(),
86+
filename: `index.html`,
87+
// favicon: './favicon.ico',
88+
// title: title,
89+
inject: true,
90+
hash: true, //开启hash ?[hash]
91+
// chunks: chunks,
92+
minify: isDev
93+
? false
94+
: {
95+
removeComments: true, //移除HTML中的注释
96+
collapseWhitespace: true, //折叠空白区域 也就是压缩代码
97+
removeAttributeQuotes: true, //去除属性引用
98+
},
99+
}),
100+
new webpack.optimize.ModuleConcatenationPlugin(),
101+
],
102+
};

build/webpack.dev.conf.js

+40-41
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
const path = require('path');
2-
const webpack = require("webpack");
3-
const merge = require("webpack-merge");
2+
const webpack = require('webpack');
3+
const merge = require('webpack-merge');
44
const webpackConfigBase = require('./webpack.base.conf');
55
const Dashboard = require('webpack-dashboard');
6-
const DashboardPlugin = require('webpack-dashboard/plugin')
6+
const DashboardPlugin = require('webpack-dashboard/plugin');
77
const dashboard = new Dashboard();
88

99
const webpackConfigDev = {
10-
mode: 'development', // 通过 mode 声明开发环境
11-
devServer: {
12-
contentBase: path.join(__dirname, "../src"),
13-
publicPath:'/', // 与上下文(output的publicPath)的保持一致
14-
host: "127.0.0.1",
15-
port: "8090",
16-
overlay: true, // 浏览器页面上显示错误
17-
// open: true, // 开启浏览器
18-
// stats: "errors-only", //stats: "errors-only"表示只打印错误:
19-
hot: true, // 开启热更新
20-
quiet: true,
21-
disableHostCheck: true,
22-
historyApiFallback: true,
23-
//服务器代理配置项
24-
proxy: {
25-
'/test/*':{
26-
target: 'https://www.baidu.com',
27-
secure: true,
28-
changeOrigin: true
29-
}
30-
}
31-
},
32-
plugins: [
33-
//热更新
34-
new webpack.HotModuleReplacementPlugin(),
35-
36-
new webpack.DefinePlugin({
37-
'process.env.NODE_ENV': '"development"'
38-
}),
10+
mode: 'development', // 通过 mode 声明开发环境
11+
devServer: {
12+
contentBase: path.join(__dirname, '../src'),
13+
publicPath: '/', // 与上下文(output的publicPath)的保持一致
14+
host: '127.0.0.1',
15+
port: '8090',
16+
overlay: true, // 浏览器页面上显示错误
17+
// open: true, // 开启浏览器
18+
// stats: "errors-only", //stats: "errors-only"表示只打印错误:
19+
hot: true, // 开启热更新
20+
quiet: true,
21+
disableHostCheck: true,
22+
historyApiFallback: true,
23+
//服务器代理配置项
24+
proxy: {
25+
'/test/*': {
26+
target: 'https://www.baidu.com',
27+
secure: true,
28+
changeOrigin: true,
29+
},
30+
},
31+
},
32+
plugins: [
33+
//热更新
34+
new webpack.HotModuleReplacementPlugin(),
3935

40-
new DashboardPlugin(dashboard.setData),
41-
42-
],
43-
devtool: "source-map", // 开启调试模式
44-
module: {
45-
rules: []
46-
},
47-
}
48-
module.exports = merge(webpackConfigBase, webpackConfigDev);
36+
new webpack.DefinePlugin({
37+
'process.env.NODE_ENV': '"development"',
38+
}),
39+
40+
new DashboardPlugin(dashboard.setData),
41+
],
42+
devtool: 'source-map', // 开启调试模式
43+
module: {
44+
rules: [],
45+
},
46+
};
47+
module.exports = merge(webpackConfigBase, webpackConfigDev);

0 commit comments

Comments
 (0)