Skip to content

Commit 8d3bcec

Browse files
committed
feat: update webpack
1 parent d50f98f commit 8d3bcec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+12113
-10891
lines changed

.babelrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.eslintrc.js

100644100755
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
// https://eslint.org/docs/user-guide/configuring
2-
3-
module.exports = {
4-
root: true,
5-
parserOptions: {
6-
parser: 'babel-eslint'
7-
},
8-
env: {
9-
browser: true,
10-
},
11-
extends: [
12-
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
13-
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
14-
'plugin:vue/essential',
15-
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
16-
'standard'
17-
],
18-
// required to lint *.vue files
19-
plugins: [
20-
'vue'
21-
],
22-
// add your custom rules here
23-
rules: {
24-
// allow async-await
25-
'generator-star-spacing': 'off',
26-
// allow debugger during development
27-
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
28-
}
29-
}
1+
module.exports = {
2+
extends: [
3+
'standard',
4+
'plugin:vue/recommended'
5+
],
6+
rules: {
7+
8+
},
9+
globals: {
10+
__webpack_public_path__: true
11+
}
12+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ yarn-error.log*
88
/test/unit/coverage/
99
/test/e2e/reports/
1010
selenium-debug.log
11+
.example/
1112

1213
# Editor directories and files
1314
.idea

.npmrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.stylelintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "stylelint-config-standard",
3+
"ignoreFiles": ["./node_modules/**/*.css","./dist/**/*.css"]
4+
}

babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@vue/app'
5+
]
6+
],
7+
plugins: [
8+
[
9+
'@babel/plugin-transform-runtime',{
10+
corejs: 3,
11+
}
12+
]
13+
]
14+
}

build/build.js

100644100755
Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
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, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
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-
})
1+
const webpack = require('webpack')
2+
const ora = require('ora')
3+
const chalk = require('chalk')
4+
const webpackConfig = require('./config')
5+
6+
webpackConfig().then(({ prodConfig }) => {
7+
const isAnalyzer = process.argv[2] === 'analyzer'
8+
if (isAnalyzer) {
9+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
10+
prodConfig.plugins.push(
11+
new BundleAnalyzerPlugin()
12+
)
13+
}
14+
const spinner = ora('Builing for production...').start()
15+
webpack(prodConfig, (err, stats) => {
16+
spinner.stop()
17+
if (err) throw err
18+
process.stdout.write(stats.toString({
19+
modules: false,
20+
colors: true,
21+
// 添加 children 信息
22+
children: false,
23+
// 添加 chunk 信息(设置为 `false` 能允许较少的冗长输出)
24+
chunks: false,
25+
// 将构建模块信息添加到 chunk 信息
26+
chunkModules: false
27+
}) + '\n\n')
28+
if (stats.hasErrors()) {
29+
console.log(chalk.red('Build failed with errors.\n'))
30+
process.exit(1)
31+
}
32+
console.log(chalk.cyan('Build complete.\n'))
33+
if (!isAnalyzer) process.exit(0)
34+
})
35+
})

build/check-versions.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

build/config/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
6+
<title>vue-code-diff</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<!-- built files will be auto injected -->
11+
</body>
12+
</html>

build/config/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const portfinder = require('portfinder')
2+
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
3+
const ProgressBarWebpackPlugin = require('progress-bar-webpack-plugin')
4+
const chalk = require('chalk')
5+
const webpackProdConfig = require('./webpack.prod')
6+
const webpackDevConfig = require('./webpack.dev')
7+
8+
module.exports = async () => {
9+
portfinder.basePort = 3010
10+
const port = await portfinder.getPortPromise()
11+
webpackDevConfig.devServer.port = port
12+
13+
webpackDevConfig.plugins.push(
14+
new FriendlyErrorsWebpackPlugin(
15+
{
16+
compilationSuccessInfo: {
17+
messages: [`You application is running here http://localhost:${port}`]
18+
}
19+
}
20+
)
21+
)
22+
webpackDevConfig.plugins.push(new ProgressBarWebpackPlugin({
23+
format: `:msg [${chalk.green(':bar')}]${chalk.yellow.bold(':percent')} (:elapseds)`,
24+
complete: ':',
25+
incomplete: ' '
26+
}))
27+
return {
28+
devConfig: webpackDevConfig,
29+
prodConfig: webpackProdConfig
30+
}
31+
}

build/config/utils.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2+
const cssLoader = {
3+
less: {
4+
loader: 'less-loader',
5+
options: {
6+
javascriptEnabled: true,
7+
strictMath: false
8+
}
9+
},
10+
scss: {
11+
loader: 'sass-loader'
12+
},
13+
postcss: {
14+
loader: 'postcss-loader'
15+
}
16+
}
17+
function baseCssLoader (type, prod) {
18+
return {
19+
test: new RegExp(`\.(${type})$`),
20+
use: [
21+
prod
22+
? {
23+
loader: MiniCssExtractPlugin.loader,
24+
options: {
25+
publicPath: '../../'
26+
}
27+
}
28+
: 'style-loader',
29+
'css-loader',
30+
'postcss-loader',
31+
cssLoader[type]
32+
]
33+
}
34+
}
35+
36+
function setBaseCssLoaders (types = [], prod = false) {
37+
return [
38+
{
39+
test: /\.(css)$/,
40+
use: [
41+
prod
42+
? {
43+
loader: MiniCssExtractPlugin.loader,
44+
options: {
45+
publicPath: '../../'
46+
}
47+
}
48+
: 'style-loader',
49+
'css-loader'
50+
]
51+
},
52+
...types.map(type => baseCssLoader(type, prod))
53+
]
54+
}
55+
56+
module.exports = {
57+
setBaseCssLoaders
58+
}

build/config/webpack.analyzer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
2+
const prodConfig = require('./webpack.prod')
3+
4+
prodConfig.plugins.push(
5+
new BundleAnalyzerPlugin()
6+
)
7+
8+
module.exports = prodConfig

0 commit comments

Comments
 (0)