Skip to content

Commit

Permalink
feat: [构建] 添加 排除 第三方包 功能
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Aug 21, 2019
1 parent 76eb2f9 commit aeb5584
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 10 deletions.
19 changes: 19 additions & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ declare namespace build {
*/
webpack?: options.webpack

/**
* exclude 排除 第三方包
*/
exclude?: options.exclude

/**
* 服务器端 插件 配置
* * 中间件
Expand Down Expand Up @@ -355,6 +360,20 @@ declare namespace build {
server?: serverConfig
}

/**
* exclude 排除 第三方包
*/
interface exclude {
/**
* 排除 客户端 第三方包
*/
client?: string[]
/**
* 排除 服务器端 第三方包
*/
server?: string[]
}

interface serverConfig extends Configuration {
nodeExternalsWhitelist: any[]
webpack: Configuration
Expand Down
4 changes: 4 additions & 0 deletions doc/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default function(inject: ConfigOptions.getOptionsInject): ConfigOptions.o
return {
env: ['SERVER_ENV', 'ENV', 'NODE_ENV'],
port,
exclude: {
client: ['globals'],
server: ['@bestminr/fastblur'],
},
babelrc: {
presets: [
[
Expand Down
12 changes: 11 additions & 1 deletion doc/build/webpack.base.conf.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export default function(config, { resolve }) {
loader: 'worker-loader',
options: { inline: true },
},
{
test: /.*\.wasm$/,
// This is needed to make webpack NOT process wasm files.
// See https://github.com/webpack/webpack/issues/6725
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: '[name].[hash:5].[ext]',
},
},
],
},
}
}
}
6 changes: 5 additions & 1 deletion doc/build/webpack.client.conf.babel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
export default function(config, { resolve }) {
return {
entry: {
app: ['./src/entry-client.ts'],
},
output: {
globalObject: 'this',
}
},
plugins: [
// new BundleAnalyzerPlugin()
]
}
}
2 changes: 1 addition & 1 deletion doc/build/webpack.server.conf.babel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function(config, { resolve }) {
return {
entry: './src/entry-server.ts',
entry: './src/entry-server.ts'
}
}
2 changes: 2 additions & 0 deletions doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"devDependencies": {
"@babel/plugin-syntax-jsx": "^7.2.0",
"@babel/runtime": "^7.1.5",
"@bestminr/fastblur": "^0.1.1",
"@types/babel-core": "^6.25.5",
"@types/bluebird": "3.5.18",
"@types/express": "^4.16.0",
Expand All @@ -74,6 +75,7 @@
"ts-jest": "^24.0.0",
"ts-node-dev": "^1.0.0-pre.39",
"vue-jest": "^3.0.4",
"webpack-bundle-analyzer": "^3.4.1",
"worker-loader": "^2.0.0"
}
}
15 changes: 15 additions & 0 deletions doc/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ import Component from 'vue-class-component'
import { State } from 'vuex-class'
import { Watch, Prop } from 'vue-property-decorator'
import axios from 'axios'
import { isServer, injectGlobal } from 'src/envs'
function get(url: string) {
if (isServer) url = `${injectGlobal.__INJECT_CONTEXT__.SERVER_HOST}${url}`
console.log('axios 发起请求:', url)
axios.get(url).then(({ data }) => {
console.log('axios 获取当前版本号:', data.version.join('.'))
})
}
@Component({
components: {},
})
export default class App extends Vue {
created() {
get('/private/version')
}
mounted() {
console.log('init APP')
}
Expand Down
21 changes: 21 additions & 0 deletions doc/src/views/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ import { Trouter } from '@types'
import { commit, getState } from 'src/store'
import { isServer } from 'src/envs'
import fastblur from '@bestminr/fastblur'
let fastblurWasmModulePromise: Promise<typeof import('@bestminr/fastblur')>
function getFastBlurModule(): Promise<typeof import('@bestminr/fastblur')> {
return import('@bestminr/fastblur').then((m) => {
if (fastblurWasmModulePromise) {
return fastblurWasmModulePromise
}
const wasmPath = require('@bestminr/fastblur/fastblur_bg.wasm') // 使用 file-loader 处理的时候是酱紫的
console.log('got module', m, wasmPath)
// wasm-bindgen 生成的 js 和 d.ts 不太对... 只好这样强行调 init 函数了
const initPromise = (m as any).default(wasmPath)
fastblurWasmModulePromise = initPromise.then(() => {
return m
})
return fastblurWasmModulePromise
}).catch((err) => {
console.log('err', err)
}) as any
}
@Component({
components: {},
Expand Down Expand Up @@ -43,6 +63,7 @@ export default class APP extends Vue {
mounted() {
console.log('init Views')
getFastBlurModule()
}
addTestHotLoadingVuex() {
Expand Down
84 changes: 82 additions & 2 deletions doc/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@
webpack-node-externals "^1.7.2"
webpackbar "^3.1.3"

"@bestminr/fastblur@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@bestminr/fastblur/-/fastblur-0.1.1.tgz#ed89586624ed668cdd15a6f9e25446019a91db6a"

"@cnakazawa/watch@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef"
Expand Down Expand Up @@ -1288,6 +1292,10 @@ acorn-walk@^6.0.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.1.1.tgz#d363b66f5fac5f018ff9c3a1e7b6f8e310cc3913"

acorn-walk@^6.1.1:
version "6.2.0"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.2.0.tgz#123cb8f3b84c2171f1f7fb252615b1c78a6b1a8c"

acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
Expand All @@ -1300,6 +1308,10 @@ acorn@^6.0.1, acorn@^6.0.5:
version "6.1.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.1.1.tgz#7d25ae05bb8ad1f9b699108e1094ecd7884adc1f"

acorn@^6.0.7:
version "6.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.3.0.tgz#0087509119ffa4fc0a0041d1e93a417e68cb856e"

ajv-errors@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
Expand Down Expand Up @@ -1774,6 +1786,15 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

bfj@^6.1.1:
version "6.1.2"
resolved "https://registry.yarnpkg.com/bfj/-/bfj-6.1.2.tgz#325c861a822bcb358a41c78a33b8e6e2086dde7f"
dependencies:
bluebird "^3.5.5"
check-types "^8.0.3"
hoopy "^0.1.4"
tryer "^1.0.1"

big.js@^3.1.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e"
Expand Down Expand Up @@ -2156,6 +2177,10 @@ chardet@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"

check-types@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/check-types/-/check-types-8.0.3.tgz#3356cca19c889544f2d7a95ed49ce508a0ecf552"

chokidar@^2.0.2, chokidar@^2.0.4:
version "2.1.6"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.6.tgz#b6cad653a929e244ce8a834244164d241fa954c5"
Expand Down Expand Up @@ -2329,7 +2354,7 @@ commander@2.17.x:
version "2.17.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"

commander@^2.12.1, commander@^2.19.0, commander@~2.20.0:
commander@^2.12.1, commander@^2.18.0, commander@^2.19.0, commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"

Expand Down Expand Up @@ -3017,6 +3042,10 @@ dot-prop@^4.1.1:
dependencies:
is-obj "^1.0.0"

duplexer@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"

duplexify@^3.4.2, duplexify@^3.6.0:
version "3.7.1"
resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309"
Expand Down Expand Up @@ -3052,6 +3081,10 @@ ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"

ejs@^2.6.1:
version "2.6.2"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.6.2.tgz#3a32c63d1cd16d11266cd4703b14fec4e74ab4f6"

electron-to-chromium@^1.3.164:
version "1.3.165"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.165.tgz#51864c9e3c9bd9e1c020b9493fddcc0f49888e3a"
Expand Down Expand Up @@ -3363,7 +3396,7 @@ expect@^24.8.0:
jest-message-util "^24.8.0"
jest-regex-util "^24.3.0"

express@^4.17.1:
express@^4.16.3, express@^4.17.1:
version "4.17.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134"
dependencies:
Expand Down Expand Up @@ -3533,6 +3566,10 @@ filename-regex@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"

filesize@^3.6.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-3.6.1.tgz#090bb3ee01b6f801a8a8be99d31710b3422bb317"

filewatcher@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/filewatcher/-/filewatcher-3.0.1.tgz#f4a1957355ddaf443ccd78a895f3d55e23c8a034"
Expand Down Expand Up @@ -3933,6 +3970,13 @@ growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"

gzip-size@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"
dependencies:
duplexer "^0.1.1"
pify "^4.0.1"

handlebars@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.1.2.tgz#b6b37c1ced0306b221e094fc7aca3ec23b131b67"
Expand Down Expand Up @@ -4054,6 +4098,10 @@ homedir-polyfill@^1.0.1:
dependencies:
parse-passwd "^1.0.0"

hoopy@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d"

hosted-git-info@^2.1.4:
version "2.7.1"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047"
Expand Down Expand Up @@ -6031,6 +6079,10 @@ onetime@^2.0.0:
dependencies:
mimic-fn "^1.0.0"

opener@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.1.tgz#6d2f0e77f1a0af0032aca716c2c1fbb8e7e8abed"

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
Expand Down Expand Up @@ -8181,6 +8233,10 @@ trough@^1.0.0:
dependencies:
glob "^7.1.2"

tryer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"

ts-jest@^24.0.0:
version "24.0.2"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d"
Expand Down Expand Up @@ -8734,6 +8790,24 @@ webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"

webpack-bundle-analyzer@^3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-3.4.1.tgz#430544c7ba1631baccf673475ca8300cb74a3c47"
dependencies:
acorn "^6.0.7"
acorn-walk "^6.1.1"
bfj "^6.1.1"
chalk "^2.4.1"
commander "^2.18.0"
ejs "^2.6.1"
express "^4.16.3"
filesize "^3.6.1"
gzip-size "^5.0.0"
lodash "^4.17.15"
mkdirp "^0.5.1"
opener "^1.5.1"
ws "^6.0.0"

webpack-cli@^3.1.2:
version "3.3.4"
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.4.tgz#de27e281c48a897b8c219cb093e261d5f6afe44a"
Expand Down Expand Up @@ -8953,6 +9027,12 @@ ws@^5.2.0:
dependencies:
async-limiter "~1.0.0"

ws@^6.0.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
dependencies:
async-limiter "~1.0.0"

x-is-string@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/x-is-string/-/x-is-string-0.1.0.tgz#474b50865af3a49a9c4657f05acd145458f77d82"
Expand Down
5 changes: 4 additions & 1 deletion src/config/webpack.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import webpack from 'webpack'
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'

import { ConfigOptions } from '@types'
import { getClientDllPlugin } from 'src/utils/plugins.webpack'
import { getClientDllPlugin, getExternals } from 'src/utils/plugins.webpack'

export async function getClientConfig(options: ConfigOptions.options) {
const client = options.webpack ? options.webpack.client || {} : {}
const externals = getExternals(options, 'client')

return (merge as any)(
getBaseConfig(options),
{
name: 'client',
entry: {
app: './src/entry-client.js'
},
externals,
output: {
globalObject: 'this'
},
Expand Down
Loading

0 comments on commit aeb5584

Please sign in to comment.