mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
tooling(webpack): move webpack to its own folder (#6076)
This commit is contained in:
parent
905373f294
commit
cdb202d8ba
176
.webpack/webpack.common.js
Normal file
176
.webpack/webpack.common.js
Normal file
@ -0,0 +1,176 @@
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/** @type {import('webpack').Configuration} */
|
||||
const config = {
|
||||
context: path.join(__dirname, ".."),
|
||||
entry: {
|
||||
openmct: "./openmct.js",
|
||||
generatorWorker: "./example/generator/generatorWorker.js",
|
||||
couchDBChangesFeed:
|
||||
"./src/plugins/persistence/couch/CouchChangesFeed.js",
|
||||
inMemorySearchWorker: "./src/api/objects/InMemorySearchWorker.js",
|
||||
espressoTheme: "./src/plugins/themes/espresso-theme.scss",
|
||||
snowTheme: "./src/plugins/themes/snow-theme.scss"
|
||||
},
|
||||
output: {
|
||||
globalObject: "this",
|
||||
filename: "[name].js",
|
||||
path: path.resolve(__dirname, "..", "dist"),
|
||||
library: "openmct",
|
||||
libraryTarget: "umd",
|
||||
publicPath: "",
|
||||
hashFunction: "xxhash64",
|
||||
clean: true
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.join(__dirname, "..", "src"),
|
||||
legacyRegistry: path.join(__dirname, "..", "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": path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"node_modules/d3-scale/dist/d3-scale.min.js"
|
||||
),
|
||||
printj: path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"node_modules/printj/dist/printj.min.js"
|
||||
),
|
||||
styles: path.join(__dirname, "..", "src/styles"),
|
||||
MCT: path.join(__dirname, "..", "src/MCT"),
|
||||
testUtils: path.join(__dirname, "..", "src/utils/testUtils.js"),
|
||||
objectUtils: path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"src/api/objects/object-utils.js"
|
||||
),
|
||||
utils: path.join(__dirname, "..", "src/utils")
|
||||
}
|
||||
},
|
||||
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"
|
||||
}
|
||||
]
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: "[name].css",
|
||||
chunkFilename: "[name].css"
|
||||
})
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(sc|sa|c)ss$/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
{
|
||||
loader: "css-loader"
|
||||
},
|
||||
{
|
||||
loader: "resolve-url-loader"
|
||||
},
|
||||
{
|
||||
loader: "sass-loader",
|
||||
options: { sourceMap: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: "vue-loader"
|
||||
},
|
||||
{
|
||||
test: /\.html$/,
|
||||
type: "asset/source"
|
||||
},
|
||||
{
|
||||
test: /\.(jpg|jpeg|png|svg)$/,
|
||||
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: 25000000,
|
||||
maxAssetSize: 25000000
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
@ -6,9 +6,9 @@ OpenMCT Continuous Integration servers use this configuration to add code covera
|
||||
information to pull requests.
|
||||
*/
|
||||
|
||||
const config = require('./webpack.dev');
|
||||
const config = require("./webpack.dev");
|
||||
// eslint-disable-next-line no-undef
|
||||
const CI = process.env.CI === 'true';
|
||||
const CI = process.env.CI === "true";
|
||||
|
||||
config.devtool = CI ? false : undefined;
|
||||
|
||||
@ -18,13 +18,18 @@ config.module.rules.push({
|
||||
test: /\.js$/,
|
||||
exclude: /(Spec\.js$)|(node_modules)/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
loader: "babel-loader",
|
||||
options: {
|
||||
retainLines: true,
|
||||
// eslint-disable-next-line no-undef
|
||||
plugins: [['babel-plugin-istanbul', {
|
||||
extension: ['.js', '.vue']
|
||||
}]]
|
||||
plugins: [
|
||||
[
|
||||
"babel-plugin-istanbul",
|
||||
{
|
||||
extension: [".js", ".vue"]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
@ -5,28 +5,28 @@ This configuration should be used for development purposes. It contains full sou
|
||||
devServer (which be invoked using by `npm start`), and a non-minified Vue.js distribution.
|
||||
If OpenMCT is to be used for a production server, use webpack.prod.js instead.
|
||||
*/
|
||||
const { merge } = require('webpack-merge');
|
||||
const common = require('./webpack.common');
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common");
|
||||
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: 'development',
|
||||
mode: "development",
|
||||
watchOptions: {
|
||||
// Since we use require.context, webpack is watching the entire directory.
|
||||
// We need to exclude any files we don't want webpack to watch.
|
||||
// See: https://webpack.js.org/configuration/watch/#watchoptions-exclude
|
||||
ignored: [
|
||||
'**/{node_modules,dist,docs,e2e}', // All files in node_modules, dist, docs, e2e,
|
||||
'**/{*.yml,Procfile,webpack*.js,babel*.js,package*.json,tsconfig.json}', // Config files
|
||||
'**/*.{sh,md,png,ttf,woff,svg}', // Non source files
|
||||
'**/.*' // dotfiles and dotfolders
|
||||
"**/{node_modules,dist,docs,e2e}", // All files in node_modules, dist, docs, e2e,
|
||||
"**/{*.yml,Procfile,webpack*.js,babel*.js,package*.json,tsconfig.json}", // Config files
|
||||
"**/*.{sh,md,png,ttf,woff,svg}", // Non source files
|
||||
"**/.*" // dotfiles and dotfolders
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"vue": path.join(__dirname, "node_modules/vue/dist/vue.js")
|
||||
vue: path.join(__dirname, "..", "node_modules/vue/dist/vue.js")
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
@ -34,20 +34,20 @@ module.exports = merge(common, {
|
||||
__OPENMCT_ROOT_RELATIVE__: '"dist/"'
|
||||
})
|
||||
],
|
||||
devtool: 'eval-source-map',
|
||||
devtool: "eval-source-map",
|
||||
devServer: {
|
||||
devMiddleware: {
|
||||
writeToDisk: (filePathString) => {
|
||||
const filePath = path.parse(filePathString);
|
||||
const shouldWrite = !(filePath.base.includes('hot-update'));
|
||||
const shouldWrite = !filePath.base.includes("hot-update");
|
||||
|
||||
return shouldWrite;
|
||||
}
|
||||
},
|
||||
watchFiles: ['**/*.css'],
|
||||
watchFiles: ["**/*.css"],
|
||||
static: {
|
||||
directory: path.join(__dirname, '/dist'),
|
||||
publicPath: '/dist',
|
||||
directory: path.join(__dirname, "..", "/dist"),
|
||||
publicPath: "/dist",
|
||||
watch: false
|
||||
},
|
||||
client: {
|
@ -4,17 +4,17 @@
|
||||
This configuration should be used for production installs.
|
||||
It is the default webpack configuration.
|
||||
*/
|
||||
const { merge } = require('webpack-merge');
|
||||
const common = require('./webpack.common');
|
||||
const { merge } = require("webpack-merge");
|
||||
const common = require("./webpack.common");
|
||||
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: 'production',
|
||||
mode: "production",
|
||||
resolve: {
|
||||
alias: {
|
||||
"vue": path.join(__dirname, "node_modules/vue/dist/vue.min.js")
|
||||
vue: path.join(__dirname, "..", "node_modules/vue/dist/vue.min.js")
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
@ -22,5 +22,5 @@ module.exports = merge(common, {
|
||||
__OPENMCT_ROOT_RELATIVE__: '""'
|
||||
})
|
||||
],
|
||||
devtool: 'source-map'
|
||||
devtool: "source-map"
|
||||
});
|
@ -28,12 +28,12 @@ module.exports = (config) => {
|
||||
let singleRun;
|
||||
|
||||
if (process.env.KARMA_DEBUG) {
|
||||
webpackConfig = require('./webpack.dev.js');
|
||||
browsers = ['ChromeDebugging'];
|
||||
webpackConfig = require("./.webpack/webpack.dev.js");
|
||||
browsers = ["ChromeDebugging"];
|
||||
singleRun = false;
|
||||
} else {
|
||||
webpackConfig = require('./webpack.coverage.js');
|
||||
browsers = ['ChromeHeadless'];
|
||||
webpackConfig = require("./.webpack/webpack.coverage.js");
|
||||
browsers = ["ChromeHeadless"];
|
||||
singleRun = true;
|
||||
}
|
||||
|
||||
@ -42,28 +42,28 @@ module.exports = (config) => {
|
||||
delete webpackConfig.entry;
|
||||
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', 'webpack'],
|
||||
basePath: "",
|
||||
frameworks: ["jasmine", "webpack"],
|
||||
files: [
|
||||
'indexTest.js',
|
||||
"indexTest.js",
|
||||
// included means: should the files be included in the browser using <script> tag?
|
||||
// We don't want them as a <script> because the shared worker source
|
||||
// needs loaded remotely by the shared worker process.
|
||||
{
|
||||
pattern: 'dist/couchDBChangesFeed.js*',
|
||||
pattern: "dist/couchDBChangesFeed.js*",
|
||||
included: false
|
||||
},
|
||||
{
|
||||
pattern: 'dist/inMemorySearchWorker.js*',
|
||||
pattern: "dist/inMemorySearchWorker.js*",
|
||||
included: false
|
||||
},
|
||||
{
|
||||
pattern: 'dist/generatorWorker.js*',
|
||||
pattern: "dist/generatorWorker.js*",
|
||||
included: false
|
||||
}
|
||||
],
|
||||
port: 9876,
|
||||
reporters: ['spec', 'junit', 'coverage-istanbul'],
|
||||
reporters: ["spec", "junit", "coverage-istanbul"],
|
||||
browsers,
|
||||
client: {
|
||||
jasmine: {
|
||||
@ -73,8 +73,8 @@ module.exports = (config) => {
|
||||
},
|
||||
customLaunchers: {
|
||||
ChromeDebugging: {
|
||||
base: 'Chrome',
|
||||
flags: ['--remote-debugging-port=9222'],
|
||||
base: "Chrome",
|
||||
flags: ["--remote-debugging-port=9222"],
|
||||
debug: true
|
||||
}
|
||||
},
|
||||
@ -90,7 +90,7 @@ module.exports = (config) => {
|
||||
fixWebpackSourcePaths: true,
|
||||
skipFilesWithNoCoverage: true,
|
||||
dir: "coverage/unit", //Sets coverage file to be consumed by codecov.io
|
||||
reports: ['lcovonly']
|
||||
reports: ["lcovonly"]
|
||||
},
|
||||
specReporter: {
|
||||
maxLogLines: 5,
|
||||
@ -102,11 +102,11 @@ module.exports = (config) => {
|
||||
failFast: false
|
||||
},
|
||||
preprocessors: {
|
||||
'indexTest.js': ['webpack', 'sourcemap']
|
||||
"indexTest.js": ["webpack", "sourcemap"]
|
||||
},
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: {
|
||||
stats: 'errors-warnings'
|
||||
stats: "errors-warnings"
|
||||
},
|
||||
concurrency: 1,
|
||||
singleRun,
|
||||
|
12
package.json
12
package.json
@ -71,14 +71,14 @@
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./dist ./node_modules ./package-lock.json",
|
||||
"clean-test-lint": "npm run clean; npm install; npm run test; npm run lint",
|
||||
"start": "npx webpack serve --config ./webpack.dev.js",
|
||||
"start:coverage": "npx webpack serve --config ./webpack.coverage.js",
|
||||
"start": "npx webpack serve --config ./.webpack/webpack.dev.js",
|
||||
"start:coverage": "npx webpack serve --config ./.webpack/webpack.coverage.js",
|
||||
"lint": "eslint example src e2e --ext .js,.vue openmct.js --max-warnings=0",
|
||||
"lint:fix": "eslint example src e2e --ext .js,.vue openmct.js --fix",
|
||||
"build:prod": "webpack --config webpack.prod.js",
|
||||
"build:dev": "webpack --config webpack.dev.js",
|
||||
"build:coverage": "webpack --config webpack.coverage.js",
|
||||
"build:watch": "webpack --config webpack.dev.js --watch",
|
||||
"build:prod": "webpack --config ./.webpack/webpack.prod.js",
|
||||
"build:dev": "webpack --config ./.webpack/webpack.dev.js",
|
||||
"build:coverage": "webpack --config ./.webpack/webpack.coverage.js",
|
||||
"build:watch": "webpack --config ./.webpack/webpack.dev.js --watch",
|
||||
"info": "npx envinfo --system --browsers --npmPackages --binaries --languages --markdown",
|
||||
"test": "karma start",
|
||||
"test:debug": "KARMA_DEBUG=true karma start",
|
||||
|
@ -1,160 +0,0 @@
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/** @type {import('webpack').Configuration} */
|
||||
const config = {
|
||||
entry: {
|
||||
openmct: './openmct.js',
|
||||
generatorWorker: './example/generator/generatorWorker.js',
|
||||
couchDBChangesFeed: './src/plugins/persistence/couch/CouchChangesFeed.js',
|
||||
inMemorySearchWorker: './src/api/objects/InMemorySearchWorker.js',
|
||||
espressoTheme: './src/plugins/themes/espresso-theme.scss',
|
||||
snowTheme: './src/plugins/themes/snow-theme.scss',
|
||||
},
|
||||
output: {
|
||||
globalObject: 'this',
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
library: 'openmct',
|
||||
libraryTarget: 'umd',
|
||||
publicPath: '',
|
||||
hashFunction: 'xxhash64',
|
||||
clean: true
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.join(__dirname, "src"),
|
||||
"legacyRegistry": path.join(__dirname, "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": path.join(__dirname, "node_modules/d3-scale/dist/d3-scale.min.js"),
|
||||
"printj": path.join(__dirname, "node_modules/printj/dist/printj.min.js"),
|
||||
"styles": path.join(__dirname, "src/styles"),
|
||||
"MCT": path.join(__dirname, "src/MCT"),
|
||||
"testUtils": path.join(__dirname, "src/utils/testUtils.js"),
|
||||
"objectUtils": path.join(__dirname, "src/api/objects/object-utils.js"),
|
||||
"utils": path.join(__dirname, "src/utils")
|
||||
}
|
||||
},
|
||||
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'
|
||||
}
|
||||
]
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '[name].css',
|
||||
chunkFilename: '[name].css'
|
||||
})
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(sc|sa|c)ss$/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
{
|
||||
loader: 'css-loader'
|
||||
},
|
||||
{
|
||||
loader: 'resolve-url-loader'
|
||||
},
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {sourceMap: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: 'vue-loader'
|
||||
},
|
||||
{
|
||||
test: /\.html$/,
|
||||
type: 'asset/source'
|
||||
},
|
||||
{
|
||||
test: /\.(jpg|jpeg|png|svg)$/,
|
||||
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: 25000000,
|
||||
maxAssetSize: 25000000
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
Loading…
Reference in New Issue
Block a user