Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(webpack): first pass on better webpack build #7038

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d04d575
chore: wip
evenstensberg Sep 6, 2023
f5efdc5
chore: wip
evenstensberg Sep 6, 2023
ee41585
chore: wip
evenstensberg Sep 6, 2023
e6b752a
chore: wip
evenstensberg Sep 6, 2023
d85246d
chore: remove old reference
evenstensberg Sep 6, 2023
7fec46f
Merge branch 'master' into feat/webpack
evenstensberg Sep 6, 2023
ff93e51
chore: wip
evenstensberg Sep 6, 2023
fed625e
fix: css generation
evenstensberg Sep 14, 2023
a7cbedc
chore: rebase
evenstensberg Oct 15, 2023
5e3b091
fix: dont declare environment
evenstensberg Oct 17, 2023
987ebef
chore: clean up configs
evenstensberg Oct 19, 2023
e2298af
Merge branch 'master' into feat/webpack
evenstensberg Oct 19, 2023
2513d0f
chore: host path resolve in higher scope
evenstensberg Oct 19, 2023
c8016e3
fix: proper devserver config
evenstensberg Oct 20, 2023
a489178
chore: brainfart
evenstensberg Oct 20, 2023
9537110
chore: keep old props
evenstensberg Oct 20, 2023
990576b
Merge branch 'master' into feat/webpack
evenstensberg Oct 21, 2023
4f6ba74
Merge branch 'master' into feat/webpack
evenstensberg Oct 23, 2023
b76d566
Merge branch 'master' into feat/webpack
evenstensberg Oct 25, 2023
2974e47
Merge branch 'master' into feat/webpack
evenstensberg Nov 2, 2023
9c3acfa
Merge branch 'master' into feat/webpack
evenstensberg Nov 3, 2023
bfd61d5
Merge branch 'master' into feat/webpack
evenstensberg Nov 13, 2023
2b230d8
fix: clock reset
evenstensberg Nov 13, 2023
82f2dc6
Merge branch 'master' into feat/webpack
evenstensberg Nov 17, 2023
ef67729
chore: wip
evenstensberg Nov 17, 2023
2277346
fix: outputpath
evenstensberg Nov 17, 2023
d035b00
Merge branch 'master' into feat/webpack
evenstensberg Nov 18, 2023
89b1361
Merge branch 'master' into feat/webpack
evenstensberg Nov 22, 2023
1e9f055
chore: review comments
evenstensberg Nov 22, 2023
6b679d7
fix: use defaults in terser
evenstensberg Dec 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 218 additions & 0 deletions .webpack/webpack.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/* global __dirname module */

/*
This is the OpenMCT common webpack file. It is imported by the other three webpack configurations:
- webpack.prod.js - the production configuration for OpenMCT (default)
- webpack.dev.js - the development configuration for OpenMCT
- webpack.coverage.js - imports webpack.dev.js and adds code coverage
There are separate npm scripts to use these configurations, though simply running `npm install`
will use the default production configuration.
*/
const path = require('path');

const packageDefinition = require('../package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const { VueLoaderPlugin } = require('vue-loader');
let gitRevision = 'error-retrieving-revision';
let gitBranch = 'error-retrieving-branch';

try {
gitRevision = require('child_process').execSync('git rev-parse HEAD').toString().trim();
gitBranch = require('child_process')
.execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim();
} catch (err) {
console.warn(err);
}

//TODO: (@evenstensberg) bundle css in its own config
const isModularizeCss = true;

function setImportPath(p) {
const projectRootDir = path.resolve(__dirname, '..');
return path.resolve(projectRootDir, p);
}

let plugins = [
new webpack.DefinePlugin({
__OPENMCT_VERSION__: `'${packageDefinition.version}'`,
__OPENMCT_BUILD_DATE__: `'${new Date()}'`,
__OPENMCT_REVISION__: `'${gitRevision}'`,
__OPENMCT_BUILD_BRANCH__: `'${gitBranch}'`
}),
new VueLoaderPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: 'src/images/favicons',
to: 'favicons'
},
{
from: './index.html',
transform: function (content) {
return content.toString().replace(/dist\//g, '');
}
},
{
from: 'src/plugins/imagery/layers',
to: 'imagery'
}
]
})
];

// Important! This loader needs to always be first in (test: /css/scss/less)
function setCSSLoader(env) {
if (isModularizeCss || env === 'production') {
return {
loader: MiniCssExtractPlugin.loader
};
}
return {
loader: 'style-loader'
};
}

function setPostCssLoader(env) {
if (env === 'production') {
return {
loader: 'postcss-loader',
options: {
sourceMap: true
}
};
}
return '';
}
/** @type {import('webpack').Configuration} */
const config = function (env) {
if (isModularizeCss || env === 'production') {
plugins.push(
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: 'chunks/[id].[contenthash].css'
})
);
}

return {
context: path.resolve(__dirname, '..'),
entry: {
openmct: setImportPath('openmct.js'),
generatorWorker: setImportPath('example/generator/generatorWorker.js'),
couchDBChangesFeed: setImportPath('src/plugins/persistence/couch/CouchChangesFeed.js'),
inMemorySearchWorker: setImportPath('src/api/objects/InMemorySearchWorker.js'),
espressoTheme: setImportPath('src/plugins/themes/espresso-theme.scss'),
snowTheme: setImportPath('src/plugins/themes/snow-theme.scss')
},
output: {
globalObject: 'this',
// TODO (@evenstensberg): generate application in addition to local dev build
filename: '[name].js',
chunkFilename: 'chunks/[name].chunk.[fullhash].js',
path: setImportPath('dist'),
library: 'openmct',
libraryTarget: 'umd',
publicPath: 'auto',
hashFunction: 'xxhash64',
clean: true
},
resolve: {
alias: {
'@': setImportPath('src'),
legacyRegistry: setImportPath('src/legacyRegistry'),
saveAs: 'file-saver/src/FileSaver.js',
csv: 'comma-separated-values',
EventEmitter: 'eventemitter3',
bourbon: 'bourbon.scss',
'plotly-basic': 'plotly.js-basic-dist',
'plotly-gl2d': 'plotly.js-gl2d-dist',
'd3-scale': setImportPath('node_modules/d3-scale/dist/d3-scale.min.js'),
printj: setImportPath('node_modules/printj/dist/printj.min.js'),
styles: setImportPath('src/styles'),
MCT: setImportPath('src/MCT'),
testUtils: setImportPath('src/utils/testUtils.js'),
objectUtils: setImportPath('src/api/objects/object-utils.js'),
utils: setImportPath('src/utils'),
vue: setImportPath('node_modules/@vue/compat/dist/vue.esm-bundler.js')
},
extensions: ['.ts', '.css', '.scss', '.js', '.vue']
},
plugins,
module: {
rules: [
{
test: /\.(sc|sa|c)ss$/,
use: [
setCSSLoader(env),
{
loader: 'css-loader',
options: {
sourceMap: env !== 'production'
evenstensberg marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
loader: 'resolve-url-loader'
},
setPostCssLoader(env),
{
loader: 'sass-loader',
// resolve-url-loader needs all loaders below its decl to have sourcemaps enabled
options: { sourceMap: true }
}
]
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
compilerOptions: {
whitespace: 'preserve',
compatConfig: {
MODE: 2
}
}
}
},
{
test: /\.html$/,
type: 'asset/source'
},
{
test: /\.(png|jpg|jpeg|gif|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]'
}
},
{
test: /\.ico$/,
type: 'asset/resource',
generator: {
filename: 'icons/[name][ext]'
}
},
{
test: /\.(woff|woff2?|eot|ttf)$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]'
}
}
]
},
stats: 'errors-warnings',
performance: {
// We should eventually consider chunking to decrease
// these values
maxEntrypointSize: 27000000,
maxAssetSize: 27000000
}
};
};

module.exports = config;
171 changes: 0 additions & 171 deletions .webpack/webpack.common.js

This file was deleted.

Loading