mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
chore: build dev distribution (#251)
This commit is contained in:
@@ -20,6 +20,9 @@
|
|||||||
"import/no-extraneous-dependencies": [2, { "devDependencies": true }],
|
"import/no-extraneous-dependencies": [2, { "devDependencies": true }],
|
||||||
"import/no-dynamic-require": 0
|
"import/no-dynamic-require": 0
|
||||||
},
|
},
|
||||||
|
"globals": {
|
||||||
|
"__NEBULA_DEV__": false
|
||||||
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": ["apis/**/*"],
|
"files": ["apis/**/*"],
|
||||||
@@ -27,6 +30,12 @@
|
|||||||
"no-console": "error"
|
"no-console": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"files": ["apis/*/index.js"],
|
||||||
|
"rules": {
|
||||||
|
"global-require": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"files": ["**/*.{int,comp,spec}.{js,jsx}"],
|
"files": ["**/*.{int,comp,spec}.{js,jsx}"],
|
||||||
"env": {
|
"env": {
|
||||||
|
|||||||
5
apis/locale/index.js
Normal file
5
apis/locale/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
module.exports = require('./dist/locale.js');
|
||||||
|
} else {
|
||||||
|
module.exports = require('./dist/locale.dev.js');
|
||||||
|
}
|
||||||
@@ -10,10 +10,11 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/qlik-oss/nebula.js.git"
|
"url": "https://github.com/qlik-oss/nebula.js.git",
|
||||||
|
"directory": "apis/locale"
|
||||||
},
|
},
|
||||||
"main": "dist/locale.js",
|
"main": "index.js",
|
||||||
"module": "dist/locale.esm.js",
|
"module": "dist/locale.esm",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
|||||||
5
apis/nucleus/index.js
Normal file
5
apis/nucleus/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
module.exports = require('./dist/nucleus.js');
|
||||||
|
} else {
|
||||||
|
module.exports = require('./dist/nucleus.dev.js');
|
||||||
|
}
|
||||||
@@ -10,10 +10,13 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/qlik-oss/nebula.js.git"
|
"url": "https://github.com/qlik-oss/nebula.js.git",
|
||||||
|
"directory": "apis/nucleus"
|
||||||
},
|
},
|
||||||
"main": "dist/nucleus.js",
|
"main": "index.js",
|
||||||
"module": "dist/nucleus.esm.js",
|
"module": "dist/nucleus.esm",
|
||||||
|
"jsdelivr": "dist/nucleus.js",
|
||||||
|
"unpkg": "dist/nucleus.js",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe('app-theme', () => {
|
|||||||
error: sandbox.spy(),
|
error: sandbox.spy(),
|
||||||
warn: sandbox.spy(),
|
warn: sandbox.spy(),
|
||||||
};
|
};
|
||||||
[{ default: appThemeFn }] = aw.mock([['**/apis/theme/**/theme.js', () => t]], ['../app-theme']);
|
[{ default: appThemeFn }] = aw.mock([[require.resolve('@nebula.js/theme'), () => t]], ['../app-theme']);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe('type', () => {
|
|||||||
satisfies = sb.stub();
|
satisfies = sb.stub();
|
||||||
[{ default: create }] = aw.mock(
|
[{ default: create }] = aw.mock(
|
||||||
[
|
[
|
||||||
['**/dist/supernova.js', () => SNFactory],
|
[require.resolve('@nebula.js/supernova'), () => SNFactory],
|
||||||
['**/semver/functions/satisfies.js', () => satisfies],
|
['**/semver/functions/satisfies.js', () => satisfies],
|
||||||
['**/load.js', () => ({ load })],
|
['**/load.js', () => ({ load })],
|
||||||
],
|
],
|
||||||
|
|||||||
5
apis/supernova/index.js
Normal file
5
apis/supernova/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
module.exports = require('./dist/supernova.js');
|
||||||
|
} else {
|
||||||
|
module.exports = require('./dist/supernova.dev.js');
|
||||||
|
}
|
||||||
@@ -10,10 +10,13 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/qlik-oss/nebula.js.git"
|
"url": "https://github.com/qlik-oss/nebula.js.git",
|
||||||
|
"directory": "apis/supernova"
|
||||||
},
|
},
|
||||||
"main": "dist/supernova.js",
|
"main": "index.js",
|
||||||
"module": "dist/supernova.esm.js",
|
"module": "dist/supernova.esm",
|
||||||
|
"jsdelivr": "dist/supernova.js",
|
||||||
|
"unpkg": "dist/supernova.js",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
|||||||
5
apis/theme/index.js
Normal file
5
apis/theme/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
module.exports = require('./dist/theme.js');
|
||||||
|
} else {
|
||||||
|
module.exports = require('./dist/theme.dev.js');
|
||||||
|
}
|
||||||
@@ -10,10 +10,11 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/qlik-oss/nebula.js.git"
|
"url": "https://github.com/qlik-oss/nebula.js.git",
|
||||||
|
"directory": "apis/theme"
|
||||||
},
|
},
|
||||||
"main": "dist/theme.js",
|
"main": "index.js",
|
||||||
"module": "dist/theme.esm.js",
|
"module": "dist/theme.esm",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -7,3 +7,5 @@ module.exports = {
|
|||||||
exclude: ['**/commands/**', '**/__stories__/**'],
|
exclude: ['**/commands/**', '**/__stories__/**'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
global.__NEBULA_DEV__ = false; // eslint-disable-line
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
const babelPath = require.resolve('babel-loader');
|
const babelPath = require.resolve('babel-loader');
|
||||||
@@ -38,7 +39,7 @@ const cfg = ({ srcDir, distDir, dev = false, serveConfig = {} }) => {
|
|||||||
: {}),
|
: {}),
|
||||||
fixtures: path.resolve(process.cwd(), 'test/component'),
|
fixtures: path.resolve(process.cwd(), 'test/component'),
|
||||||
},
|
},
|
||||||
extensions: ['.js', '.jsx'],
|
extensions: ['.dev.js', '.js', '.jsx'],
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
@@ -82,6 +83,9 @@ const cfg = ({ srcDir, distDir, dev = false, serveConfig = {} }) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
__NEBULA_DEV__: true,
|
||||||
|
}),
|
||||||
new MonacoWebpackPlugin({ languages: ['json'] }),
|
new MonacoWebpackPlugin({ languages: ['json'] }),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: path.resolve(srcDir, 'eRender.html'),
|
template: path.resolve(srcDir, 'eRender.html'),
|
||||||
|
|||||||
@@ -56,9 +56,9 @@
|
|||||||
"d3-require": "1.2.4",
|
"d3-require": "1.2.4",
|
||||||
"enigma.js": "2.6.3",
|
"enigma.js": "2.6.3",
|
||||||
"monaco-editor": "0.19.2",
|
"monaco-editor": "0.19.2",
|
||||||
|
"monaco-editor-webpack-plugin": "1.8.2",
|
||||||
"react": "16.12.0",
|
"react": "16.12.0",
|
||||||
"react-dom": "16.12.0",
|
"react-dom": "16.12.0",
|
||||||
"webpack-cli": "3.3.10",
|
"webpack-cli": "3.3.10"
|
||||||
"monaco-editor-webpack-plugin": "1.8.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,33 @@ const cwd = process.cwd();
|
|||||||
const pkg = require(path.join(cwd, 'package.json')); // eslint-disable-line
|
const pkg = require(path.join(cwd, 'package.json')); // eslint-disable-line
|
||||||
const { name, version, license } = pkg;
|
const { name, version, license } = pkg;
|
||||||
|
|
||||||
|
const targetName = name.split('/')[1];
|
||||||
|
const targetDirName = 'dist';
|
||||||
|
const targetDir = path.join(cwd, targetDirName);
|
||||||
|
|
||||||
|
const getFileName = (format, dev) => `${targetName}${format ? `.${format}` : ''}${dev ? '.dev' : ''}.js`;
|
||||||
|
const getTargetFileName = (format, dev) => `${targetDirName}/${getFileName(format, dev)}`;
|
||||||
|
|
||||||
|
// verify package targets and names
|
||||||
|
if (pkg.main !== 'index.js') {
|
||||||
|
throw Error(`main target must be index.js`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in our webpack/rollup configs we include '.dev.js' as file extension when building
|
||||||
|
// a dev distribution, the module target should therefore end with '.esm' and not with '.esm.js'
|
||||||
|
// so that the node resolve algorithm finds the correct module based on module format and dev mode
|
||||||
|
// e.g. '@nebula.js/supernova' -> '@nebula.js/supernova/dist/supernova.esm.dev.js'
|
||||||
|
const moduleTargetName = getTargetFileName('esm').replace(/\.js$/, '');
|
||||||
|
if (pkg.module && pkg.module !== moduleTargetName) {
|
||||||
|
throw Error(`module target must be ${moduleTargetName}`);
|
||||||
|
}
|
||||||
|
if (pkg.unpkg && pkg.unpkg !== getTargetFileName('')) {
|
||||||
|
throw Error(`unpkg target must be ${getTargetFileName('')}`);
|
||||||
|
}
|
||||||
|
if (pkg.jsdelivr && pkg.jsdelivr !== getTargetFileName('')) {
|
||||||
|
throw Error(`jsdelivr target must be ${getTargetFileName('')}`);
|
||||||
|
}
|
||||||
|
|
||||||
const banner = `/*
|
const banner = `/*
|
||||||
* ${name} v${version}
|
* ${name} v${version}
|
||||||
* Copyright (c) ${new Date().getFullYear()} QlikTech International AB
|
* Copyright (c) ${new Date().getFullYear()} QlikTech International AB
|
||||||
@@ -56,11 +83,8 @@ const propTypes = [
|
|||||||
|
|
||||||
const watch = process.argv.indexOf('-w') > 2;
|
const watch = process.argv.indexOf('-w') > 2;
|
||||||
|
|
||||||
const config = isEsm => {
|
const config = (isEsm, dev = false) => {
|
||||||
const outputFile = isEsm ? pkg.module : pkg.main;
|
const umdName = targetName
|
||||||
const basename = path.basename(outputFile);
|
|
||||||
const dir = path.dirname(outputFile);
|
|
||||||
const umdName = basename
|
|
||||||
.replace(/-([a-z])/g, (m, p1) => p1.toUpperCase())
|
.replace(/-([a-z])/g, (m, p1) => p1.toUpperCase())
|
||||||
.split('.js')
|
.split('.js')
|
||||||
.join('');
|
.join('');
|
||||||
@@ -88,22 +112,23 @@ const config = isEsm => {
|
|||||||
const cfg = {
|
const cfg = {
|
||||||
input: path.resolve(cwd, 'src', 'index'),
|
input: path.resolve(cwd, 'src', 'index'),
|
||||||
output: {
|
output: {
|
||||||
file: path.resolve(dir, basename),
|
file: path.resolve(targetDir, getFileName(isEsm ? 'esm' : '', dev)),
|
||||||
format: isEsm ? 'esm' : 'umd',
|
format: isEsm ? 'esm' : 'umd',
|
||||||
exports: 'default',
|
exports: 'default',
|
||||||
name: umdName,
|
name: umdName,
|
||||||
sourcemap: process.env.CODESANDBOX ? 'inline' : true,
|
sourcemap: false,
|
||||||
banner,
|
banner,
|
||||||
globals,
|
globals,
|
||||||
},
|
},
|
||||||
external,
|
external,
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
|
__NEBULA_DEV__: dev,
|
||||||
'process.env.NODE_ENV': JSON.stringify(isEsm ? 'development' : 'production'),
|
'process.env.NODE_ENV': JSON.stringify(isEsm ? 'development' : 'production'),
|
||||||
'process.env.NEBULA_VERSION': JSON.stringify(version),
|
'process.env.NEBULA_VERSION': JSON.stringify(version),
|
||||||
}),
|
}),
|
||||||
nodeResolve({
|
nodeResolve({
|
||||||
extensions: ['.js', '.jsx'],
|
extensions: [dev ? '.dev.js' : false, '.js', '.jsx'].filter(Boolean),
|
||||||
}),
|
}),
|
||||||
json(),
|
json(),
|
||||||
commonjs({
|
commonjs({
|
||||||
@@ -158,7 +183,7 @@ const config = isEsm => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production' && !isEsm) {
|
if (!dev) {
|
||||||
cfg.plugins.push(
|
cfg.plugins.push(
|
||||||
terser({
|
terser({
|
||||||
output: {
|
output: {
|
||||||
@@ -171,4 +196,16 @@ const config = isEsm => {
|
|||||||
return cfg;
|
return cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = [watch ? false : config(), pkg.module ? config(true) : false].filter(Boolean);
|
const dist = [
|
||||||
|
// production
|
||||||
|
watch ? false : config(),
|
||||||
|
// dev
|
||||||
|
watch ? false : config(false, true),
|
||||||
|
|
||||||
|
// esm
|
||||||
|
pkg.module ? config(true) : false,
|
||||||
|
// esm dev
|
||||||
|
pkg.module ? config(true, true) : false,
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = dist.filter(Boolean);
|
||||||
|
|||||||
Reference in New Issue
Block a user