Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Taoja committed Dec 23, 2019
1 parent 86416c8 commit c215470
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 190 deletions.
4 changes: 2 additions & 2 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function build (options) {

if (isDev) {
var server = new webpackDevServer(compiler, options.devServer)
for (var key in config.dev.proxy) {
server.use(key, httpProxyMiddleware(config.dev.proxy[key]))
for (var key in options.devServer.proxy) {
server.use(key, httpProxyMiddleware(options.devServer.proxy[key]))
}
server.listen(options.devServer.port, options.devServer.host, ()=> {
if (options.devServer.openPage) {
Expand Down
18 changes: 0 additions & 18 deletions bin/splitter.js

This file was deleted.

24 changes: 6 additions & 18 deletions config/io.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
const entrys = require('../lib/ps')
const resolve = require('../lib/resolve')
const config = require('../lib/config')
const {type} = require('../lib/args')

var io = {}
if (type === 'multi') {
io = {
entry: entrys,
output: {
path: resolve(config.default.output),
filename: `[name]-[hash].js`,
publicPath: '../../'
}
}
} else {
io = {
entry: entrys,
output: {
path: resolve(config.default.output),
filename: `[name]-[hash].js`
}
var io = {
entry: entrys,
output: {
path: resolve(config.default.output),
filename: `[name].js`,
publicPath: '../../'
}
}
module.exports = io
14 changes: 10 additions & 4 deletions config/optimization.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ const config = require('../lib/config')

var chunksDefault = {
name: 'chunk',
test: /[\\/]common|assets|components|node_modules[\\/]/,
test: /[\\/]assets[\\/]/,
minChunks: 2
}

var chunksConfig = {
...chunksDefault,
...config.default.chunks
}
var name = chunksConfig.name
delete chunksConfig.name
Expand All @@ -27,11 +26,18 @@ choices.forEach((e) => {
...chunksConfig
}
})
var splitChunks = {
...config.default.optimization.splitChunks || {}
}

delete config.default.optimization.splitChunks
module.exports = {
splitChunks: {
cacheGroups: {
default: false,
...splitChunksGroup
}
}
},
...splitChunks
},
...config.default.optimization
}
5 changes: 1 addition & 4 deletions config/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { type } = require('../lib/args')
const build = require('../bin/build')

const {entry, output} = require('./io')
Expand All @@ -9,9 +8,7 @@ const optimization = require('./optimization')
const op = function () {
var options = public

if (type === 'multi') {
options.optimization = optimization
}
options.optimization = optimization
options.entry = entry
options.output = output
options.plugins = plugins
Expand Down
60 changes: 19 additions & 41 deletions config/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')

const config = require('../lib/config')
const {path, publicPath} = require('./static')
const {isDev, type, dashboard} = require('../lib/args')
const {isDev, dashboard} = require('../lib/args')
const resolve = require('../lib/resolve')
const entrys = require('../lib/ps')

Expand All @@ -17,23 +17,13 @@ if (dashboard) {
var dashboardConfig = new Dashboard();
}

var chunksDefault = {
name: 'chunk',
test: /[\\/]common|assets|components|node_modules[\\/]/
}

var {name} = {
...chunksDefault,
...config.default.chunks
}

var configEnv = {}
var configGlobal = {}
for (key in config.default.global) {
configGlobal[key] = JSON.stringify(config.default.global[key])
for (key in config.global) {
configGlobal[key] = JSON.stringify(config.global[key])
}
for (key in config.default.env) {
configEnv[key] = JSON.stringify(config.default.env[key])
for (key in config.env) {
configEnv[key] = JSON.stringify(config.env[key])
}
var plugins = [
new setConf(),
Expand All @@ -58,33 +48,21 @@ if (isDev) {
}


if (type === 'multi') {
var HWPs = []
for (var item in entrys) {
HWPs.push(
new HtmlWebpackPlugin({ //入口配置
filename: `${item}.html`,// 生成文件名
template: 'index.html', // 模板文件
chunks: [`${item}`, `${item.split('/')[0]}/${name}`],
static: publicPath + path
})
)
}
plugins = [
...HWPs,
...plugins,
...config.default.plugins
]
} else {
plugins = [
var HWPs = []
for (var item in entrys) {
HWPs.push(
new HtmlWebpackPlugin({ //入口配置
filename: `index.html`,// 生成文件名
filename: `${item}.html`,// 生成文件名
template: 'index.html', // 模板文件
chunks: [`${path}/js/main`],
static: path
}),
...plugins,
...config.default.plugins
]
chunks: [`${item}`, `${item.split('/')[0]}/chunk`],
static: publicPath + path,
hash: true
})
)
}
plugins = [
...HWPs,
...plugins,
...config.default.plugins
]
module.exports = plugins
23 changes: 8 additions & 15 deletions config/public.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { isDev, type } = require('../lib/args')
const { isDev } = require('../lib/args')
const config = require('../lib/config')

module.exports = {
mode: isDev ? 'development' : 'production',
devtool: isDev ? config.dev.devtool : config.build.devtool,
devtool: config.default.devtool,
devServer: {
clientLogLevel: 'warning',
host: config.dev.host, // 服务器的IP地址,可以使用IP也可以使用localhost
host: '0.0.0.0', // 服务器的IP地址,可以使用IP也可以使用localhost
compress: true, // 服务端压缩是否开启
port: config.dev.port, // 端口
port: 8082, // 端口
hot: true, //热替换
noInfo: true,
overlay: { //页面弹出错误信息
Expand All @@ -17,22 +17,15 @@ module.exports = {
},
progress: true, //输出进度到控制台
quiet: true,
openPage: config.dev.open
...config.default.devServer
},
performance: {
hints: false
hints: false,
...config.default.performance
},
externals: config.default.externals,
resolve: config.default.resolve,
module: {
rules: [
...config.default.loader,
type === 'single' ? {
test: /src[\/|\\]modules[\/|\\][_a-zA-Z0-9]+[\/|\\][_a-zA-Z0-9]+[\/|\\][_a-zA-Z0-9]+[\/|\\]index.js/,
use: {
loader: 'dividing/loader/pagesLoader.js',
}
} : {}
]
...config.default.module
}
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ global._G = {}

var args = process.argv
var argEnv = args.filter((e) => {
return e in config.default.env
return e in config.env
})
var argPackage = args.filter((e) => {
return packages.indexOf(e) >= 0
Expand Down
1 change: 0 additions & 1 deletion lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ const args = process.argv

module.exports = {
isDev: args.includes('development'),
type: args.includes('single') ? 'single' : 'multi',
dashboard: args.includes('dashboard')
}
4 changes: 2 additions & 2 deletions lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const readline = require('readline')
const config = require('./config')
function env () {
var envs = []
for(var i in config.default.env) {
for(var i in config.env) {
envs.push(i)
}
var defaultEnv
for (var i in config.default.env) {
for (var i in config.env) {
defaultEnv = i
break
}
Expand Down
17 changes: 0 additions & 17 deletions loader/pagesLoader.js

This file was deleted.

43 changes: 0 additions & 43 deletions loader/routerLoader.js

This file was deleted.

23 changes: 0 additions & 23 deletions loader/splitter-url-loader.js

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c215470

Please sign in to comment.