gisthreemap
Version:
基于webGL的三维api
96 lines (95 loc) • 3.24 kB
JavaScript
// The path to the CesiumJS source code
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
context: __dirname,
entry: {
criska_cesium: "./src/cesium.index.js",
},
mode: 'production',
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, './dist'),
publicPath: './', //设置打包后文件路径,避免异步加载文件路径错误
library: 'ThreeMapClass',
libraryTarget: 'umd',
libraryExport: 'default',
globalObject: "this",
umdNamedDefine: true,
},
amd: {
// Enable webpack-friendly use of require in Cesium
toUrlUndefined: true
},
resolve: {
alias: {
cesium: path.resolve(__dirname, cesiumSource)
},
mainFiles: ['index', 'Cesium']
},
performance: {
hints: false
},
module: {
rules: [{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
use: ['url-loader']
}, {
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'assets/fonts'
}
},
]
},{
test: /\.js$/, exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env'
],
plugins: [
[require("@babel/plugin-transform-runtime"), { "legacy": true }],
[require("@babel/plugin-proposal-class-properties"), { "legacy": true }]
]
}
}
]
}]
},
optimization: {
minimizer: [new UglifyJsPlugin()],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public/index.html'), // 使用的HTML模板
filename: 'index.html', // 打包生成到的HTML文件名
}),
// Copy Cesium Assets, Widgets, and Workers to a static directory
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' },
{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' },
{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' }
]
}),
new webpack.DefinePlugin({
// Define relative base path in cesium for loading assets
CESIUM_BASE_URL: JSON.stringify('')
})
],
devtool: 'eval'
}