From 280223dc51be6af7c6ba7ee0a0bc5702bdfca0ff Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Sat, 9 Feb 2019 23:14:51 +0100 Subject: [PATCH] Add npm build script --- .gitignore | 3 ++- package.json | 19 +++++++------ entry.ts => src/demo/index.js | 6 ++--- tsconfig.json | 11 ++++---- tslint.json | 2 +- webpack.config.js | 51 ++++++++++++++++++++--------------- 6 files changed, 52 insertions(+), 40 deletions(-) rename entry.ts => src/demo/index.js (86%) diff --git a/.gitignore b/.gitignore index d26c746..67cebfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -dist/ \ No newline at end of file +dist/ +lib/ \ No newline at end of file diff --git a/package.json b/package.json index 8e9e58a..823483c 100644 --- a/package.json +++ b/package.json @@ -1,31 +1,34 @@ { "name": "tgview", + "private": true, "version": "0.0.1", - "main": "./src/index.ts", + "main": "./lib/index.js", + "types": "./lib/index.d.ts", "license": "MIT", "scripts": { - "start": "webpack-serve", - "build": "webpack --mode production", + "build": "tsc", + "install": "tsc", + "clean": "rm -rf lib/ dist/", "lint": "tslint -p tsconfig.json" }, "devDependencies": { - "@types/jquery": "^3.3.29", - "@types/jqueryui": "^1.12.7", - "@types/jstree": "^3.3.37", - "@types/vis": "^4.21.10", "css-loader": "^2.1.0", "html-webpack-plugin": "^3.2.0", "source-map-loader": "^0.2.4", "style-loader": "^0.23.1", "ts-loader": "^5.3.3", "tslint": "^5.12.1", - "typescript": "^3.3.1", "url-loader": "^1.1.2", "webpack": "^4.29.1", "webpack-cli": "^3.2.3", "webpack-serve": "^2.0.3" }, "dependencies": { + "@types/jquery": "^3.3.29", + "@types/jqueryui": "^1.12.7", + "@types/jstree": "^3.3.37", + "@types/vis": "^4.21.10", + "typescript": "^3.3.1", "jquery": "^3.3.1", "jqueryui": "^1.11.1", "jstree": "^3.3.7", diff --git a/entry.ts b/src/demo/index.js similarity index 86% rename from entry.ts rename to src/demo/index.js index 9b588d0..5f1ea6e 100644 --- a/entry.ts +++ b/src/demo/index.js @@ -1,13 +1,13 @@ /** * @file * - * The main entry point for the TGView standalone html file + * The main entry point for the TGView demo */ -import TGView from './src'; +import TGView from '..'; // Load all of the required CSS -import './src/css/styles.css'; +import '../css/styles.css'; // import 'vis/dist/vis.min.css'; // diff --git a/tsconfig.json b/tsconfig.json index 27ca531..597f23d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,13 +4,13 @@ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - "checkJs": true, /* Report errors in .js files. */ + "allowJs": false, /* Allow javascript files to be compiled. */ + "checkJs": false, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ + "outDir": "lib/", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ @@ -57,7 +57,8 @@ "exclude": [ "webpack.config.js", "node_modules", + "src/demo", "dist", - "deps" + "lib" ] } \ No newline at end of file diff --git a/tslint.json b/tslint.json index 92fd3f3..51c76dd 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,5 @@ { - "defaultSeverity": "error", + "defaultSeverity": "warn", "jsRules": {}, "rules": { "quotemark": [true, "single"] diff --git a/webpack.config.js b/webpack.config.js index 1895564..53dbbe7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,44 +1,51 @@ -const path = require('path'); -const HTMLPlugin = require('html-webpack-plugin'); +/** + * @file + * + * This file contains configuration to run the demo locally. + */ +const path = require("path"); +const HTMLPlugin = require("html-webpack-plugin"); module.exports = { - entry: './entry.ts', - mode: 'development', - devtool: 'inline-source-map', + entry: "./src/demo", + mode: "development", + devtool: "inline-source-map", module: { rules: [ // source maps from typescript work - { test: /\.js$/, loader: 'source-map-loader', enforce: 'pre' }, - + { test: /\.js$/, loader: "source-map-loader", enforce: "pre" }, + // load typescript outside of node_modules { - test: /\.tsx?$/, - use: 'ts-loader', + test: /\.ts$/, + use: "ts-loader", exclude: /node_modules/ }, // load stylesheets -- only needed for development { - test: /\.css$/, loader: ['style-loader', 'css-loader'] - }, + test: /\.css$/, + loader: ["style-loader", "css-loader"] + }, - // load png images -- only needed for development + // load png images -- only needed for development { test: /\.(png|jpg|gif)$/, - loader: 'url-loader' + loader: "url-loader" } ] }, resolve: { - extensions: [ '.tsx', '.ts', '.js' ] + extensions: [".ts", ".js"] }, output: { - // library: 'tgview', - // libraryTarget: 'umd', - filename: 'bundle.js', - path: path.resolve(__dirname, 'dist'), - devtoolModuleFilenameTemplate: '[absolute-resource-path]' + filename: '[name].bundle.js', + path: path.resolve(__dirname, "dist"), + devtoolModuleFilenameTemplate: "[absolute-resource-path]" + }, + optimization: { + splitChunks: { + chunks: "all" + } }, - plugins: [ - new HTMLPlugin() - ] + plugins: [new HTMLPlugin()] };