add setup to compile ts files to compiled_app folder

This commit is contained in:
Labhansh Agrawal 2019-09-30 10:04:30 +05:30 committed by Benjamin Staneck
parent f07963f930
commit 7874fa813a
7 changed files with 108 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
# build output
dist
app/renderer
compiled_app
bin/cli.*
# dependencies

View file

@ -19,7 +19,9 @@ const colorList = [
'grayscale'
];
exports.getColorMap = colors => {
export const getColorMap: {
<T>(colors: T): T extends (infer U)[] ? { [k: string]: U } : T
} = colors => {
if (!Array.isArray(colors)) {
return colors;
}

22
lib/tsconfig.json Normal file
View file

@ -0,0 +1,22 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"downlevelIteration": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["dom", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"preserveConstEnums": true,
"removeComments": false,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "es6"
},
"include": [
"./**/*"
]
}

View file

@ -4,7 +4,7 @@
"repository": "zeit/hyper",
"scripts": {
"start": "echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'",
"app": "electron app",
"app": "electron compiled_app",
"dev": "webpack -w",
"build": "cross-env NODE_ENV=production webpack",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
@ -14,7 +14,8 @@
"prepush": "yarn test",
"postinstall": "electron-builder install-app-deps && yarn run rebuild-node-pty",
"rebuild-node-pty": "electron-rebuild -f -w app/node_modules/node-pty -m app",
"dist": "yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build",
"dist":
"yarn run build && cross-env BABEL_ENV=production babel --out-file compiled_app/renderer/bundle.js --no-comments --minified compiled_app/renderer/bundle.js && build",
"clean": "node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer"
},
"eslintConfig": {
@ -296,6 +297,7 @@
"husky": "0.14.3",
"inquirer": "5.1.0",
"node-gyp": "3.6.2",
"null-loader": "3.0.0",
"prettier": "1.18.2",
"proxyquire": "1.8.0",
"spectron": "3.8.0",

View file

@ -6,9 +6,9 @@
"esModuleInterop": true,
"jsx": "react",
"lib": ["dom", "es2017"],
"module": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"outDir": "./compiled_app/",
"preserveConstEnums": true,
"removeComments": false,
"resolveJsonModule": true,
@ -17,7 +17,7 @@
"target": "es6"
},
"include": [
"./lib/"
"./app/"
],
"exclude": ["node_modules", "**/node_modules/*", "bin/*", "renderer/*"]
}

View file

@ -1,4 +1,5 @@
const path = require('path');
const exec = require('child_process').exec;
const webpack = require('webpack');
const Copy = require('copy-webpack-plugin');
@ -8,6 +9,68 @@ const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
module.exports = [
{
mode: 'none',
name: 'hyper-app',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
},
entry: './app/index.js',
output: {
path: path.join(__dirname, 'compiled_app'),
filename: 'ignore_this.js'
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'null-loader'
}
]
},
plugins: [
new Copy([
{
from: './app/*.html',
exclude: /node_modules/,
to: '.',
flatten: true
},
{
from: './app/*.json',
exclude: /node_modules/,
to: '.',
flatten: true
},
{
from: './app/keymaps/*.json',
exclude: /node_modules/,
to: './keymaps',
flatten: true
}
// {
// from: './app/node_modules', // gives really long output in webpack, used cp instead
// to: './node_modules'
// }
]),
{
apply: compiler => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
exec('cp -r ./app/node_modules ./compiled_app && tsc', (err, stdout, stderr) => {
if (stdout) process.stdout.write(stdout);
if (stderr) process.stderr.write(stderr);
process.stdout.write('\nCompiled\n\n');
});
});
}
},
new ForkTsCheckerWebpackPlugin()
],
target: 'electron-main'
},
{
mode: 'none',
name: 'hyper',
@ -17,7 +80,7 @@ module.exports = [
devtool: isProd ? 'hidden-source-map' : 'cheap-module-source-map',
entry: './lib/index.js',
output: {
path: path.join(__dirname, 'app', 'renderer'),
path: path.join(__dirname, 'compiled_app', 'renderer'),
filename: 'bundle.js'
},
module: {
@ -52,7 +115,9 @@ module.exports = [
to: './assets'
}
]),
new ForkTsCheckerWebpackPlugin()
new ForkTsCheckerWebpackPlugin({
tsconfig: './lib/tsconfig.json'
})
],
target: 'electron-renderer'
},

View file

@ -6030,6 +6030,14 @@ nugget@^2.0.0:
single-line-log "^1.1.2"
throttleit "0.0.2"
null-loader@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/null-loader/-/null-loader-3.0.0.tgz#3e2b6c663c5bda8c73a54357d8fa0708dc61b245"
integrity sha512-hf5sNLl8xdRho4UPBOOeoIwT3WhjYcMUQm0zj44EhD6UscMAz72o2udpoDFBgykucdEDGIcd6SXbc/G6zssbzw==
dependencies:
loader-utils "^1.2.3"
schema-utils "^1.0.0"
num2fraction@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede"