Giter Club home page Giter Club logo

knockout-webpack-ts-quickstart's Introduction

knockout-webpack-ts-quickstart

Quickstart project for knockout.js + TypeScript + decorators with Webpack2.

npm GitHub release Travis GitHub forks GitHub stars


Features

  • Use decorators similar syntax to Angular.
    See src/app/AppModule.ts and src/app/components/*Component.ts.
  • Compile TypeScript source and output as single file with source map.
  • Compile SCSS, do auto-prefixing (PostCSS), and output as single CSS file with source map.
  • Run unit tests (jasmine).
  • Include CI configurations (Travis CI, bitbucket pipelines, Wercker, AWS CodeBuild).
  • Include Visual Studio Code debugger and tasks configurations.

Use with legacy IE (IE 7/8)

See legacy-ie-fix branch.

Usage (Starting your project)

  1. Fork and clone me.
  2. Edit package informations of package.json.
    Don't remember to change repository url, author, homepage.
  3. Edit library name and output file name of webpack.config.js.
    // [Node-single-js-file]: Packing a Node single Javascript file.
    {
        entry: {
            // TODO: YOU SHOULD REPLACE THE LIBRARY OUTPUT NAME!
            <your-output-name>: path.resolve(__dirname, 'src/index.ts')
        },
        output: {
            // TODO: YOU SHOULD REPLACE THE LIBRARY NAME!
            library: '<your-library-name>',
            ...
        },
        module: {
            rules: [{
                test: /\.tsx?$/,
                ...
    
                // TODO: YOU SHOULD REPLACE THE PACKAGE NAME!
                // exclude 'node_module' directory except myself (refered from other packages)
                exclude: /node_modules[\/\\](?!knockout-webpack-ts-quickstart).*$/
            }, {
                test: /\.jsx?$/,
                ...
    
                // TODO: YOU SHOULD REPLACE THE PACKAGE NAME!
                // exclude 'node_module' directory except myself (refered from other packages)
                exclude: /node_modules[\/\\](?!knockout-webpack-ts-quickstart).*$/
            }, {
            ...
    },
    
    // [Browser-single-js-file]: Packing a library Javascript file.
    {
        entry: {
            // TODO: YOU SHOULD REPLACE THE LIBRARY OUTPUT NAME!
            <your-output-name>: path.resolve(__dirname, 'src/index.ts')
        },
        output: {
            // TODO: YOU SHOULD REPLACE THE LIBRARY NAME!
            library: '<your-library-name>',
            ...
        },
        module: {
            rules: [{
                test: /\.tsx?$/,
                ...
    
                // TODO: YOU SHOULD REPLACE THE PACKAGE NAME!
                // exclude 'node_module' directory except myself (refered from other packages)
                exclude: /node_modules[\/\\](?!knockout-webpack-ts-quickstart).*$/
            }, {
                test: /\.jsx?$/,
                ...
    
                // TODO: YOU SHOULD REPLACE THE PACKAGE NAME!
                // exclude 'node_module' directory except myself (refered from other packages)
                exclude: /node_modules[\/\\](?!knockout-webpack-ts-quickstart).*$/
            }, {
            ...
    },
  4. Write your code.
  5. and build it.
    npm run build
    npm test

Compile SCSS Stylesheets to single CSS file.

  1. Clone me:
    git clone shellyln/knockout-webpack-ts-quickstart.git
  2. Build me:
    npm run build
    npm test
  3. Copy dist/style.min.css and dist/style.min.css.map to your site.
  4. and use:

app.html

<head>
    <link rel="stylesheet" type="text/css" href="path/to/style.min.css">
</head>

Debugging with Webpack

  1. npm start
  2. Run browser's devtools.
  3. Fix anything and save it.
  4. Go back to line 2.

Directory structure

  • /bin/ : Output directory of Node module javascript file (CommonJS) that build with tsc.
  • /dist/ : Output directory of distribution javascript single file (AMD ; for browsers) and stylesheet single file that build+packed by Webpack.
  • /declarations/ : Output directory of TypeScript declaration.
  • /spec/ : Directory of jasmine configurations.
  • /src/index.ts : Library main file.
  • /src/app.ts : Entry point file.
  • /src/app/ : Application source files.
  • /src/app/components : Components source files.
  • /src/lib/ : Directory of library program codes.
  • /src/spec/ : Directory of unit test codes. We use jasmine.
  • /src/assets/scss/ : Directory of stylesheet source.
  • /src/assets/ : Assets packed by Webpack.
  • /.babelrc : Babel configuration.
  • /.gitignore : git ignore list.
  • /.npmignore : NPM ignore list.
  • /package.json : NPM package configuration.
  • /tsconfig.json : TypeScript compiler options for Node module output. it also uses for IDEs' error checking and coding assistance.
  • /tsconfig-webpack-dist.json : TypeScript compiler options for distribution single file output.
  • /webpack.config.js : Webpack2 build configuration.
  • /.travis.yml : Travis CI test and deploying pipeline configuration.
  • /bitbucket-pipelines.yml : bitbucket pipelines test and deploying pipeline configuration.
  • /bitbucket-heroku-deploy.sh : bitbucket test and deploying pipeline helper shell script.
  • /wercker.yml : Wercker test and deploying pipeline configuration.
  • /buildspec.yml : AWS CodeBuild test and deploying pipeline configuration.
  • /buildspec-heroku-pre-deploy.sh : AWS CodeBuild test and deploying pipeline helper shell script.
  • /buildspec-heroku-deploy.sh : AWS CodeBuild test and deploying pipeline helper shell script.

NPM scripts

  • build : Build for production.
  • rebuild : Clean all output and build for production.
  • build:node:dev : Build Node module output (CommonJS) for develop.
  • build:node:prod : Build Node module output (CommonJS) for production.
  • build:dist:dev : Build distribution output (AMD) for develop.
  • build:dist:prod : Build distribution output (AMD) for production.
  • clean : Clean all output.
  • test : Run unit tests.
  • start : Run codes for debugging (bin/app.js).
  • watch : Build distribution output and watch continuously.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.