14

我当前的整个 package.json 文件。

"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"
},

我正在尝试使用 1 个watch脚本来运行 lite 服务器,构建 .ts .js 和 .css 文件。

现在,当我编辑或制作任何新的打字稿文件时,我拥有systemJStsc生成 .js 文件。

一旦从 .js 生成了这些 javascript 文件tsc:w,它们就会出现在 dist 文件夹中。一旦它们在那里更新,我想根据 dist 中的 main.js 将它们 uglify 并连接到 1 个 lifeleveler.app.js 文件中。

到目前为止,我无法正确组合上面的任务..

我的文件夹目录

在此处输入图像描述


我也认为我的方法是错误的,我可以有 2 个终端窗口。1 看 TSX -> js,另一个看 SASS-> CSS。

最后,当我准备好推送构建时,也许就是我的build:js任务。

但是我需要替换我的 index.html 文件中的块,你会怎么做?

<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
4

2 回答 2

5

您可以修改您的tsconfig.json

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

首先用于tsc:w编译成单个文件,并build:js缩小为dist/lifeleveler.app.js

编辑:请注意outFile不能一起使用"module": "commonjs"看这个问题

于 2017-02-21T04:20:59.470 回答
0

看看这个解决方案:https ://github.com/jquintozamora/react-typescript-webpack2-cssModules-postCSS

重要文件:package.json tsconfig.json webpack 文件 app 模块结构

希望有帮助!

于 2017-02-21T00:58:17.010 回答