129 lines
3.2 KiB
JavaScript
129 lines
3.2 KiB
JavaScript
/**
|
|
* Created by Zhang Haijun on 2018/7/24.
|
|
*/
|
|
const CompressPlugin = require('compress-webpack-plugin')
|
|
const { getDllPlugins } = require('./utils')
|
|
|
|
const httpType = 'http://'
|
|
const proxyUrl = '101.89.218.38:60006/' // 代理地址设置
|
|
exports.getCommonConifg = function ({ devServer, ...other }) {
|
|
return {
|
|
transpileDependencies: ['@cmp/cmp-core'],
|
|
publicPath: process.env.BASE_URL,
|
|
assetsDir: 'static',
|
|
// 构建时不进行eslint校验
|
|
lintOnSave: process.env.NODE_ENV !== 'production',
|
|
// 生产环境禁止source map
|
|
productionSourceMap: false,
|
|
devServer: {
|
|
// https: true,
|
|
headers: {
|
|
'Access-Control-Allow-Origin': '*'
|
|
},
|
|
overlay: {
|
|
warnings: true,
|
|
errors: true
|
|
},
|
|
proxy: {
|
|
'/api/sms/messageService': {
|
|
target: 'ws://' + proxyUrl,
|
|
changeOrigin: true,
|
|
ws: false
|
|
},
|
|
'/api': {
|
|
target: httpType + proxyUrl,
|
|
changeOrigin: true,
|
|
secure: false
|
|
},
|
|
'/config-files': {
|
|
target: httpType + proxyUrl
|
|
},
|
|
'/web-common-resource': {
|
|
target: httpType + proxyUrl
|
|
},
|
|
'/config': {
|
|
target: httpType + proxyUrl
|
|
},
|
|
'/cof-web': {
|
|
target: httpType + proxyUrl
|
|
}
|
|
},
|
|
...devServer
|
|
},
|
|
css: {
|
|
loaderOptions: {
|
|
sass: {
|
|
prependData: '@import "~@cmp/cmp-common/css/common-var.scss";'
|
|
}
|
|
}
|
|
},
|
|
...other
|
|
}
|
|
}
|
|
exports.commonConfigureWebpack = function (name) {
|
|
// const plugins = []
|
|
const plugins = []
|
|
if (process.env.NODE_ENV === 'production') {
|
|
plugins.push(
|
|
new CompressPlugin({
|
|
test: /\.js$|\.html$|\.css$/,
|
|
threshold: 10240,
|
|
deleteOriginalAssets: false
|
|
})
|
|
)
|
|
}
|
|
return {
|
|
plugins,
|
|
// externals: {
|
|
// vue: 'Vue',
|
|
// 'element-ui': 'ELEMENT'
|
|
// },
|
|
output: {
|
|
// 把子应用打包成 umd 库格式
|
|
library: `${name}-[name]`,
|
|
libraryTarget: 'umd',
|
|
jsonpFunction: `webpackJsonp_${name}`
|
|
}
|
|
}
|
|
}
|
|
exports.commonChainWebpack = function (config, resolve) {
|
|
// set svg-sprite-loader
|
|
config.module.rule('svg').exclude.add(resolve('src/icons')).end()
|
|
config.module
|
|
.rule('icons')
|
|
.test(/\.svg$/)
|
|
.include.add(resolve('src/icons'))
|
|
.end()
|
|
.use('svg-sprite-loader')
|
|
.loader('svg-sprite-loader')
|
|
.options({
|
|
symbolId: 'icon-[name]'
|
|
})
|
|
.end()
|
|
config.resolve.alias
|
|
.set('@', resolve('src'))
|
|
.set('assets', resolve('src/assets'))
|
|
.set('services', resolve('src/services'))
|
|
.set('utils', '@cmp/cmp-common/utils')
|
|
.set('interface', '@cmp/cmp-common/interface')
|
|
.set('components', '@cmp/cmp-common/components')
|
|
.set('hooks', '@cmp/cmp-common/hooks')
|
|
.set('filters', resolve('src/filters'))
|
|
.set('views', resolve('src/views'))
|
|
config.module
|
|
.rule('fonts')
|
|
.use('url-loader')
|
|
.loader('url-loader')
|
|
.options({
|
|
limit: 4096, // 小于4kb将会被打包成 base64
|
|
fallback: {
|
|
loader: 'file-loader',
|
|
options: {
|
|
name: 'fonts/[name].[ext]',
|
|
publicPath: '/web-common-resource'
|
|
}
|
|
}
|
|
})
|
|
.end()
|
|
}
|