14

My current entire package.json file.

"scripts": {
    "build": "webpack",
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\"",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "build:css": "node-sass --output-style compressed --include-path scss scss/lifeleveler.scss app/assets/css/app.css",
    "build:css-expand": "node-sass --include-path scss scss/lifeleveler.scss app/assets/css/app.css",
    "watch:css": "nodemon -e scss -x \"npm run build:css\"",
    "watch:css:expand": "nodemon -e scss -x \"npm run build:css-expand\"",
    "build:js": "browserify dist/main.js > dist/lifeleveler.app.js",
    "watch": "npm run watch:css & npm run watch:js",
    "watch:js": "onchange '/dist/**/*.js' -p -- npm run build:js"
},

I'm trying to have 1 single watch script that will run the lite server, build the .ts .js and .css files.

Right now I have systemJS and tsc generating .js files when I edit or make any new typescript files.

Once those javascript files are generated from the tsc:w, they end up in the dist folder. Once they are updated there I would like to uglify and concat them into 1 lifeleveler.app.js file based off the main.js inside of dist.

So far I can't combine my tasks above correctly..

My folder directory

enter image description here


I'm also thinking my approach is wrong, I can have 2 terminal windows. 1 watching TSX -> js, and the other for SASS->CSS.

Then at the end, when I'm ready to push a build, perhaps then my build:js task.

However I would need to replace blocks in my index.html file, how would you do that?

<html>
<head>
    <meta charset="UTF-8">
    <title>LifeLeveler</title>
    <meta name="description" content="Level up in the journey of life.">
    <link rel="stylesheet" href="app/assets/css/app.css">
    <!-- load the dependecies -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <!-- load our angular app with systemjs -->
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="systemjs.config.js"></script>
    <script>
        System.import('app').catch(function(err) { console.log(err); });
    </script>
    <!-- <script src="dist/lifeleveler.app.js"></script> -->
</head>
<body class="container">

    <my-app></my-app>

</body>
</html>

tsconfig

"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "rootDir": "app/",
    "outFile": "./dist/main.js",
    "outDir": "dist"
},
"sourceMap": true
1

2 Answers 2

5
+100

You can modify your tsconfig.json :

{
    "compilerOptions": {
        "target": "ES5",
        "rootDir": "app/",
        "outFile": "./dist/main.js"
    }
}

First use tsc:w to compile into a single file, and build:js to minify to dist/lifeleveler.app.js

Edit : Please note outFile can not use along with "module": "commonjs", see this question

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but hmm I tried that and getting this error: error TS6082: Only 'amd' and 'system' modules are supported alongside --outFile. I posted my tsconfig.json file in my question.
you need to remove "module": "commonjs"
Hmm still getting an error, the npm run twc:w works, but when I run npm start I get this: node_modules/@angular/common/src/pipes/async_pipe.d.ts(44,38): error TS2304: Cannot find name 'Promise mind checking out my full repo here? github.com/leongaban/lifeleveler.io
Ah thanks! Figured it out, I needed to edit my index file appropriately, also one of my modules was broken. Ok next step is figuring out npm scripts to change my index file for production :) thanks so much!
0

Take a look to this solution: https://github.com/jquintozamora/react-typescript-webpack2-cssModules-postCSS

Important files: package.json tsconfig.json webpack files app modules structure

Hope that helps!

1 Comment

Thanks! But the reason I wanted to use only NPM scripts, was to remove the need for a builder like webpack. The only thing I can't figure out how to do right now is compile everything into 1 file. After the TS watch builds the JS from the .ts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.