浏览代码

修改wepack配置

tags/1.10.2
Caven Chen 5 年前
父节点
当前提交
7327e42b74
共有 10 个文件被更改,包括 164 次插入98 次删除
  1. 7
    0
      CHANGE.md
  2. 5
    5
      dist/dc.base.min.js
  3. 1
    1
      dist/dc.core.min.js
  4. 2
    2
      package.json
  5. 22
    25
      src/base/index.js
  6. 0
    2
      src/core/index.js
  7. 12
    11
      src/core/widget/Compass.js
  8. 4
    4
      src/log.js
  9. 105
    0
      webpack.base.conf.js
  10. 6
    48
      webpack.config.js

+ 7
- 0
CHANGE.md 查看文件

# 更新 # 更新


## 1.10.2

### 2020-9-12

> 1. 完善罗盘功能
> 2. 修改框架包node下导入的方式

## 1.10.1 ## 1.10.1


### 2020-9-12 ### 2020-9-12

+ 5
- 5
dist/dc.base.min.js
文件差异内容过多而无法显示
查看文件


+ 1
- 1
dist/dc.core.min.js
文件差异内容过多而无法显示
查看文件


+ 2
- 2
package.json 查看文件

"license": "Apache 2.0", "license": "Apache 2.0",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "yarn run clean && webpack --mode development",
"publish": "yarn run clean && webpack --mode production --env.production",
"build": "yarn run clean && webpack --config webpack.base.conf --mode development && webpack --config webpack.config --mode development",
"publish": "yarn run clean && webpack --config webpack.base.conf --mode production --env.production && webpack --config webpack.config --mode production --env.production",
"clean": "rimraf dist/" "clean": "rimraf dist/"
}, },
"devDependencies": { "devDependencies": {

+ 22
- 25
src/base/index.js 查看文件



import { initMixin, initUse } from './global-api' import { initMixin, initUse } from './global-api'


delete window.DC

let DC = { let DC = {
Author: 'Caven Chen <cavencj@gmail.com>',
GitHub: 'https://github.com/dvgis/dc-sdk',
Home: 'https://www.dvgis.cn',
Author: build.author,
GitHub: build.repository,
Home: build.homepage,
Version: build.version, Version: build.version,
Namespace: {}, Namespace: {},
Initialized: false Initialized: false
} }


window.DC = DC
;(function() {
require('../log')
initMixin(window.DC)
initUse(window.DC)
let cesiumLoaded = false
DC.init = callback => {
if (!cesiumLoaded) {
new Promise((resolve, reject) => {
let Cesium = require('cesium/Cesium')
resolve(Cesium)
}).then(Cesium => {
DC.Namespace['Cesium'] = Cesium
cesiumLoaded = true
delete window.Cesium
callback && callback()
})
} else {
initMixin(DC)
initUse(DC)

let cesiumLoaded = false
DC.init = callback => {
if (!cesiumLoaded) {
new Promise((resolve, reject) => {
let Cesium = require('cesium/Cesium')
resolve(Cesium)
}).then(Cesium => {
DC.Namespace['Cesium'] = Cesium
cesiumLoaded = true
delete window.Cesium
callback && callback() callback && callback()
}
})
} else {
callback && callback()
} }
})()
}

require('../log')


export default DC export default DC

+ 0
- 2
src/core/index.js 查看文件

} }
callback && callback() callback && callback()
} catch (e) { } catch (e) {
delete window.DC
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(e) console.error(e)
} }
} }


/* istanbul ignore if */ /* istanbul ignore if */

if (typeof window !== 'undefined' && window.DC) { if (typeof window !== 'undefined' && window.DC) {
install(window.DC) install(window.DC)
} }

+ 12
- 11
src/core/widget/Compass.js 查看文件

*/ */


import { DomUtil } from '../utils' import { DomUtil } from '../utils'
import { SceneEventType } from '../event'
import Icon from '../icon' import Icon from '../icon'
import State from '../state/State' import State from '../state/State'
import Widget from './Widget' import Widget from './Widget'
} }


_bindEvent() { _bindEvent() {
this._removeSubscription = this._viewer.scene.postRender.addEventListener(
() => {
let heading = this._viewer.camera.heading
this._outRing.style.cssText = `
transform : rotate(-${heading}rad);
-webkit-transform : rotate(-${heading}rad);
`
},
this
)
this._viewer.on(SceneEventType.POST_RENDER, this._postRenderHandler, this)
} }


_unbindEvent() { _unbindEvent() {
this._removeSubscription()
this._viewer.off(SceneEventType.POST_RENDER, this._postRenderHandler, this)
} }


_installHook() { _installHook() {
} }
} }


_postRenderHandler() {
let heading = this._viewer.camera.heading
this._outRing &&
(this._outRing.style.cssText = `
transform : rotate(-${heading}rad);
-webkit-transform : rotate(-${heading}rad);
`)
}

_createCompassDom() { _createCompassDom() {
DomUtil.create('div', 'out-ring-bg', this._wrapper) DomUtil.create('div', 'out-ring-bg', this._wrapper)
this._outRing = DomUtil.parseDom(Icon.compass_outer, true, 'out-ring') this._outRing = DomUtil.parseDom(Icon.compass_outer, true, 'out-ring')

+ 4
- 4
src/log.js 查看文件

// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log( console.log(
`%c \n DC-SDK \n %c \n 用数字描绘世界之美 %c \n `%c \n DC-SDK \n %c \n 用数字描绘世界之美 %c \n
版本:${DC.Version}
版本:${build.version}
编译日期:${build.time} 编译日期:${build.time}
Cesium版本:1.73 Cesium版本:1.73
作者:${DC.Author}
主页: ${DC.Home}
github:${DC.GitHub}
作者:${build.author}
主页: ${build.homepage}
github:${build.repository}
授权信息:授权-永久使用此软件当前版本。 \n 授权信息:授权-永久使用此软件当前版本。 \n


版权声明: 版权声明:

+ 105
- 0
webpack.base.conf.js 查看文件

/**
* @Author: Caven
* @Date: 2020-01-18 19:22:23
*/

const path = require('path')
const webpack = require('webpack')
const packageInfo = require('./package.json')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const cesiumBuild = 'node_modules/cesium/Build/Cesium'

let cesiumCopyPlugin = [
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' }
]),
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' }
]),
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }
])
]

function resolve(dir) {
return path.join(__dirname, '.', dir)
}

function getTime() {
let now = new Date()
let m = now.getMonth() + 1
m = m < 10 ? '0' + m : m
let d = now.getDate()
d = d < 10 ? '0' + d : d
let h = now.getHours()
h = h < 10 ? '0' + h : h
let min = now.getMinutes()
min = min < 10 ? '0' + min : min
let s = now.getSeconds()
s = s < 10 ? '0' + s : s
return `${now.getFullYear()}-${m}-${d} ${h}:${min}:${s}`
}

module.exports = env => {
const IS_PROD = (env && env.production) || false
const publicPath = IS_PROD ? '/' : '/'
let plugins = [
...cesiumCopyPlugin,
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/'),
'build.version': JSON.stringify(packageInfo.version),
'build.time': JSON.stringify(getTime()),
'build.author': JSON.stringify(packageInfo.author),
'build.repository': JSON.stringify(packageInfo.repository),
'build.homepage': JSON.stringify(packageInfo.homepage)
})
]
if (IS_PROD) {
plugins.push(new webpack.NoEmitOnErrorsPlugin())
}
return {
entry: {
'dc.base': ['base']
},
devtool: IS_PROD ? false : 'source-map',
output: {
filename: IS_PROD ? '[name].min.js' : '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: publicPath,
library: 'DC',
libraryExport: 'default',
libraryTarget: 'umd'
},
amd: {
toUrlUndefined: true
},
node: {
fs: 'empty'
},
module: {
unknownContextCritical: false,
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/transform-runtime'],
compact: false,
ignore: ['checkTree']
}
}
]
},
resolve: {
extensions: ['.js', '.json', '.css'],
alias: {
'@': resolve('src'),
base: './src/base/index.js',
cesium: path.resolve(__dirname, cesiumBuild)
}
},
plugins
}
}

+ 6
- 48
webpack.config.js 查看文件



const path = require('path') const path = require('path')
const webpack = require('webpack') const webpack = require('webpack')
const packageInfo = require('./package.json')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin') const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const JavaScriptObfuscator = require('webpack-obfuscator') const JavaScriptObfuscator = require('webpack-obfuscator')

const cesiumBuild = 'node_modules/cesium/Build/Cesium' const cesiumBuild = 'node_modules/cesium/Build/Cesium'


let cesiumCopyPlugin = [
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'Assets'), to: 'resources/Assets' }
]),
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'Workers'), to: 'resources/Workers' }
]),
new CopyWebpackPlugin([
{ from: path.join(cesiumBuild, 'ThirdParty'), to: 'resources/ThirdParty' }
])
]

function resolve(dir) { function resolve(dir) {
return path.join(__dirname, '.', dir) return path.join(__dirname, '.', dir)
} }


function getTime() {
let now = new Date()
let m = now.getMonth() + 1
m = m < 10 ? '0' + m : m
let d = now.getDate()
d = d < 10 ? '0' + d : d
let h = now.getHours()
h = h < 10 ? '0' + h : h
let min = now.getMinutes()
min = min < 10 ? '0' + min : min
let s = now.getSeconds()
s = s < 10 ? '0' + s : s
return `${now.getFullYear()}-${m}-${d} ${h}:${min}:${s}`
}

module.exports = env => { module.exports = env => {
const IS_PROD = (env && env.production) || false const IS_PROD = (env && env.production) || false
const publicPath = IS_PROD ? '/' : '/' const publicPath = IS_PROD ? '/' : '/'
let plugins = [ let plugins = [
...cesiumCopyPlugin,
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: IS_PROD ? '[name].min.css' : '[name].css', filename: IS_PROD ? '[name].min.css' : '[name].css',
allChunks: true allChunks: true
}),
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify('./libs/dc-sdk/resources/'),
'build.version': JSON.stringify(packageInfo.version),
'build.time': JSON.stringify(getTime())
}) })
] ]
if (IS_PROD) { if (IS_PROD) {
{ {
rotateStringArray: true rotateStringArray: true
}, },
['dc.base.min.js']
[]
) )
) )
} }
return { return {
entry: { entry: {
'dc.base': ['base'],
'dc.core': ['entry', 'theme']
'dc.core': ['theme', 'entry']
}, },
devtool: IS_PROD ? false : 'cheap-module-eval-source-map',
devtool: IS_PROD ? false : 'source-map',
output: { output: {
filename: IS_PROD ? '[name].min.js' : '[name].js', filename: IS_PROD ? '[name].min.js' : '[name].js',
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
publicPath: publicPath, publicPath: publicPath,
sourcePrefix: ''
},
amd: {
toUrlUndefined: true
},
node: {
fs: 'empty'
library: 'DcCore',
libraryTarget: 'umd',
umdNamedDefine: true
}, },
module: { module: {
unknownContextCritical: false, unknownContextCritical: false,
extensions: ['.js', '.json', '.css'], extensions: ['.js', '.json', '.css'],
alias: { alias: {
'@': resolve('src'), '@': resolve('src'),
base: './src/base/index.js',
entry: './src/core/index.js', entry: './src/core/index.js',
theme: './src/themes/index.js', theme: './src/themes/index.js',
cesium: path.resolve(__dirname, cesiumBuild) cesium: path.resolve(__dirname, cesiumBuild)

正在加载...
取消
保存