Skip to content

Commit 6fb53a7

Browse files
author
Shawn Wang
committed
update build tools
1 parent 4d87564 commit 6fb53a7

File tree

8 files changed

+376
-444
lines changed

8 files changed

+376
-444
lines changed

build/run/dev-server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const { exec } = require('child_process')
2+
const chalk = require('chalk')
23
const path = require('path')
34
const projectPath = __dirname.replace(`build${path.sep}run`, '')
45
let port = process.env.port || 9000
6+
const webpackDevServerPath = path.join(projectPath, 'node_modules/.bin/webpack-dev-server')
7+
const webpackConfigPath = path.join(projectPath, 'build/webpack.config.js')
58

69
function run () {
7-
const child = exec(`${projectPath}node_modules/.bin/webpack-dev-server --config ${projectPath}build/webpack.config.js --color`, {
10+
const buildCommand = `${webpackDevServerPath} --config ${webpackConfigPath} --color`
11+
console.log(chalk.blue(buildCommand))
12+
const child = exec(buildCommand, {
813
env: {
914
port,
1015
},

build/run/production.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
const { exec, execSync } = require('child_process')
1+
const { exec } = require('child_process')
22
const path = require('path')
3+
const fs = require('fs')
4+
const fsUtils = require('nodejs-fs-utils')
5+
const chalk = require('chalk')
36
const projectPath = __dirname.replace(`build${path.sep}run`, '')
7+
const distDirPath = path.join(projectPath, 'dist')
8+
const webpackPath = path.join(projectPath, 'node_modules/.bin/webpack')
9+
const webpackConfigPath = path.join(projectPath, 'build/webpack.config.js')
410

511
function run () {
6-
execSync('rm -rf dist/*')
7-
const child = exec(`${projectPath}node_modules/.bin/webpack --config ${projectPath}build/webpack.config.js`, (error, stdout, stderr) => {
12+
console.log(chalk.red(`remove dir: ${distDirPath}`))
13+
fsUtils.removeSync(distDirPath, {
14+
skipErrors: true, fs,
15+
})
16+
const buildCommand = `${webpackPath} --config ${webpackConfigPath}`
17+
console.log(chalk.blue(buildCommand))
18+
const child = exec(buildCommand, (error, stdout, stderr) => {
819
if (error) {
920
console.error(error.message)
1021
}

build/webpack-config/dev-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const { devServerConfig } = require(`${projectPath}package.json`)
44

55
module.exports = {
66
watchContentBase: true,
7-
useLocalIp: true,
8-
open: true,
7+
useLocalIp: false,
8+
open: false,
99
clientLogLevel: 'warning',
1010
openPage: 'index.html',
1111
host: '0.0.0.0',

build/webpack-config/module.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ const { webpackConfig } = require(`${projectPath}package.json`)
66

77
module.exports = {
88
rules: [
9-
{
10-
test: /\.(ico)$/,
11-
loader: 'url-loader',
12-
options: { name: 'config/images/[name].[ext]' }
13-
},
149
{
1510
test: /\.(png|svg|jpg|gif)$/, use: [ {
1611
loader: 'file-loader',
@@ -38,14 +33,20 @@ module.exports = {
3833
},
3934
{
4035
test: /\.js$/,
41-
exclude: (resource) => {
42-
if (/node_modules/.test(resource)) {
43-
const excludeRegArray = webpackConfig.transpileModules
44-
for (let i = 0; i < excludeRegArray.length; i++) {
45-
return !resource.includes(excludeRegArray[ i ])
36+
exclude: (resourcePath) => {
37+
const transplieRegArray = [ ...webpackConfig.transpileModules ]
38+
if (/\Wnode_modules\W/.test(resourcePath)) {
39+
for (let i = 0, len = transplieRegArray.length; i < len; i++) {
40+
const transplieItem = transplieRegArray[ i ]
41+
if (typeof transplieItem === 'string') {
42+
return !resourcePath.includes(transplieItem)
43+
} else if (typeof transplieItem === 'object') {
44+
return !transplieItem.test(resourcePath)
45+
}
4646
}
4747
return true
4848
}
49+
return false
4950
},
5051
use: [ 'babel-loader' ]
5152
},

build/webpack-config/plugins.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const path = require('path')
22
const os = require('os')
33
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
44
const HtmlWebpackPlugin = require('html-webpack-plugin')
5+
const webpack = require('webpack')
56
const VueLoaderPlugin = require('vue-loader/lib/plugin')
67
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
78
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
@@ -38,6 +39,13 @@ const plugins = [
3839
},
3940
clearConsole: true,
4041
}),
42+
new webpack.IgnorePlugin({
43+
checkResource: (resourcePath) => {
44+
if (/moment\/locale\/(?!zh-cn)/.test(resourcePath)){
45+
return true
46+
}
47+
},
48+
}),
4149
new VueLoaderPlugin(),
4250
new MiniCssExtractPlugin({
4351
filename: 'css/[name].[hash].css',

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@
3535
},
3636
"devDependencies": {
3737
"@babel/core": "^7.4.4",
38+
"@babel/polyfill": "^7.4.4",
3839
"@babel/preset-env": "^7.4.4",
3940
"@types/core-js": "^2.5.0",
4041
"@types/node": "^11.13.8",
4142
"autoprefixer": "^9.5.1",
4243
"babel-loader": "^8.0.5",
44+
"chalk": "^4.0.0",
4345
"cross-env": "^5.2.0",
4446
"css-loader": "^2.1.1",
4547
"cssnano": "^4.1.10",
46-
"es3ify-loader": "^0.2.0",
4748
"extract-text-webpack-plugin": "4.0.0-beta.0",
4849
"file-loader": "^3.0.1",
4950
"friendly-errors-webpack-plugin": "^1.7.0",
5051
"html-webpack-plugin": "^3.2.0",
5152
"mini-css-extract-plugin": "^0.6.0",
52-
"node-sass": "^4.12.0",
53+
"node-sass": "^4.13.1",
54+
"nodejs-fs-utils": "^1.2.4",
5355
"optimize-css-assets-webpack-plugin": "^5.0.1",
5456
"postcss-loader": "^3.0.0",
5557
"sass": "^1.19.0",
@@ -63,7 +65,7 @@
6365
"webpack": "^4.30.0",
6466
"webpack-bundle-analyzer": "^3.3.2",
6567
"webpack-cli": "^3.3.0",
66-
"webpack-dev-server": "^3.3.1"
68+
"webpack-dev-server": "^3.8.0"
6769
},
6870
"license": "MIT"
6971
}

src/utils/date/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class DateUtils {
2-
static showCountdownAccurateToDate (timeStr: string) {
2+
static getCountdownStr(timeStr: string) {
33
const TOTAL_TIME_FOR_SECOND = 1000
44
const TOTAL_TIME_FOR_MINUTE = TOTAL_TIME_FOR_SECOND * 60
55
const TOTAL_TIME_FOR_HOUR = TOTAL_TIME_FOR_MINUTE * 60

0 commit comments

Comments
 (0)