Skip to content

Instantly share code, notes, and snippets.

@tinco
Created January 16, 2020 18:23
Show Gist options
  • Save tinco/8f423938bb9dd4fc8edc1fa86ab017b3 to your computer and use it in GitHub Desktop.
Save tinco/8f423938bb9dd4fc8edc1fa86ab017b3 to your computer and use it in GitHub Desktop.
Cesium webpack config
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cesiumPackage = require('cesium/package.json')
const cesiumTarget = 'cesium-' + cesiumPackage.version
module.exports = {
entry: './src/index.ts',
output: {
filename: 'main.[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.ts', '.js', '.json'],
alias: {
shared: path.resolve(__dirname, '../shared'),
},
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
use: ['url-loader'],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
// Copy Cesium Assets, Widgets, and Workers to a static directory
new CopyWebpackPlugin([
{ from: 'node_modules/cesium/Build/Cesium/Workers', to: path.join(cesiumTarget, 'Workers') },
]),
new CopyWebpackPlugin([
{ from: 'node_modules/cesium/Build/Cesium/ThirdParty', to: path.join(cesiumTarget, 'ThirdParty') },
]),
new CopyWebpackPlugin([{ from: 'node_modules/cesium/Build/Cesium/Assets', to: path.join(cesiumTarget, 'Assets') }]),
new CopyWebpackPlugin([
{ from: 'node_modules/cesium/Build/Cesium/Widgets', to: path.join(cesiumTarget, 'Widgets') },
]),
new webpack.DefinePlugin({
// Define relative base path in cesium for loading assets
CESIUM_BASE_URL: JSON.stringify(cesiumTarget),
}),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment