Added rollup for Tree-shaking

This commit is contained in:
William Welling
2016-12-16 15:16:03 -06:00
parent e1f141ba42
commit 6f3229fb38
8 changed files with 120 additions and 40 deletions

View File

@@ -18,18 +18,21 @@
"clean:css:shim:ts": "rimraf **/*.css.shim.ts", "clean:css:shim:ts": "rimraf **/*.css.shim.ts",
"clean:scss:shim:ts": "rimraf **/*.scss.shim.ts", "clean:scss:shim:ts": "rimraf **/*.scss.shim.ts",
"clean:prod": "npm run clean:ngc && npm run clean:json && npm run clean:css && npm run clean:css:ts && npm run clean:scss:ts && npm run clean:css:shim:ts && npm run clean:scss:shim:ts && npm run clean:dist", "clean:prod": "npm run clean:ngc && npm run clean:json && npm run clean:css && npm run clean:css:ts && npm run clean:scss:ts && npm run clean:css:shim:ts && npm run clean:scss:shim:ts && npm run clean:dist",
"clean": "npm run clean:log && npm run clean:dist && npm run clean:prod && npm run clean:node", "clean": "npm run clean:log && npm run clean:prod && npm run clean:node",
"sass": "node-sass src -o src --include-path node_modules --output-style compressed -q", "sass": "node-sass src -o src --include-path node_modules --output-style compressed -q",
"sass:watch": "node-sass -w src -o src --include-path node_modules --output-style compressed -q", "sass:watch": "node-sass -w src -o src --include-path node_modules --output-style compressed -q",
"rollup": "rollup -c rollup-server.js && rollup -c rollup-client.js",
"prebuild": "npm run clean:dist && npm run sass", "prebuild": "npm run clean:dist && npm run sass",
"build": "webpack --progress", "build": "webpack --progress",
"build:prod": "webpack --config webpack.prod.config.ts", "build:prod": "webpack --config webpack.prod.config.ts",
"build:prod:ngc": "npm run clean:prod && npm run sass && npm run ngc && npm run clean:dist && npm run build:prod", "build:prod:rollup": "npm run build:prod && npm run rollup",
"build:prod:ngc:json": "npm run clean:prod && npm run sass && npm run ngc && npm run clean:dist && npm run build:prod:json", "build:prod:ngc": "npm run clean:prod && npm run sass && npm run ngc && npm run build:prod:rollup",
"build:prod:ngc:json": "npm run clean:prod && npm run sass && npm run ngc && npm run build:prod:json:rollup",
"build:prod:json": "webpack --config webpack.prod.config.ts --json | webpack-bundle-size-analyzer", "build:prod:json": "webpack --config webpack.prod.config.ts --json | webpack-bundle-size-analyzer",
"build:prod:json:rollup": "npm run build:prod:json && npm run rollup",
"ngc": "ngc -p tsconfig.aot.json", "ngc": "ngc -p tsconfig.aot.json",
"prestart": "npm run build:prod:ngc:json", "prestart": "npm run build:prod:ngc:json",
"server": "node dist/server/index.js", "server": "node dist/server/build.js",
"server:dev": "nodemon --debug dist/server/index.js", "server:dev": "nodemon --debug dist/server/index.js",
"start": "npm run server", "start": "npm run server",
"start:dev": "npm run clean:prod && npm run build && npm run server", "start:dev": "npm run clean:prod && npm run build && npm run server",
@@ -44,24 +47,25 @@
"debug:start": "npm run build && npm run debug:server", "debug:start": "npm run build && npm run debug:server",
"debug:build": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js", "debug:build": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js",
"debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts", "debug:build:prod": "node-nightly --inspect --debug-brk node_modules/webpack/bin/webpack.js --config webpack.prod.config.ts",
"docs": "typedoc --options typedoc.json ./src",
"lint": "tslint \"src/**/*.ts\" || true", "lint": "tslint \"src/**/*.ts\" || true",
"global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer marked node-gyp" "global": "npm install -g angular-cli nodemon npm-check-updates rimraf ts-node typedoc typescript webpack webpack-bundle-size-analyzer rollup marked node-gyp"
}, },
"dependencies": { "dependencies": {
"@angular/common": "2.2.4", "@angular/common": "2.2.3",
"@angular/compiler": "2.2.4", "@angular/compiler": "2.2.3",
"@angular/compiler-cli": "2.2.4", "@angular/compiler-cli": "2.2.3",
"@angular/core": "2.2.4", "@angular/core": "2.2.3",
"@angular/forms": "2.2.4", "@angular/forms": "2.2.3",
"@angular/http": "2.2.4", "@angular/http": "2.2.3",
"@angular/platform-browser": "2.2.4", "@angular/platform-browser": "2.2.3",
"@angular/platform-browser-dynamic": "2.2.4", "@angular/platform-browser-dynamic": "2.2.3",
"@angular/platform-server": "2.2.4", "@angular/platform-server": "2.2.3",
"@angular/router": "3.2.4", "@angular/router": "3.2.3",
"@angular/upgrade": "2.2.4", "@angular/upgrade": "2.2.3",
"@angularclass/bootloader": "1.0.1", "@angularclass/bootloader": "1.0.1",
"@angularclass/idle-preload": "1.0.4", "@angularclass/idle-preload": "1.0.4",
"@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.14", "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.15",
"@ngrx/core": "^1.2.0", "@ngrx/core": "^1.2.0",
"@ngrx/effects": "^2.0.0", "@ngrx/effects": "^2.0.0",
"@ngrx/router-store": "^1.2.5", "@ngrx/router-store": "^1.2.5",
@@ -86,7 +90,7 @@
"zone.js": "0.6.26" "zone.js": "0.6.26"
}, },
"devDependencies": { "devDependencies": {
"@ngtools/webpack": "1.1.7", "@ngtools/webpack": "1.1.9",
"@types/body-parser": "0.0.33", "@types/body-parser": "0.0.33",
"@types/compression": "0.0.33", "@types/compression": "0.0.33",
"@types/cookie-parser": "1.3.30", "@types/cookie-parser": "1.3.30",
@@ -96,26 +100,31 @@
"@types/memory-cache": "0.0.29", "@types/memory-cache": "0.0.29",
"@types/mime": "0.0.29", "@types/mime": "0.0.29",
"@types/morgan": "1.7.32", "@types/morgan": "1.7.32",
"@types/node": "6.0.51", "@types/node": "6.0.52",
"@types/serve-static": "1.7.31", "@types/serve-static": "1.7.31",
"@types/webfontloader": "1.6.27", "@types/webfontloader": "1.6.27",
"angular2-template-loader": "0.6.0", "angular2-template-loader": "0.6.0",
"autoprefixer": "6.5.3", "autoprefixer": "6.5.4",
"awesome-typescript-loader": "2.2.4", "awesome-typescript-loader": "2.2.4",
"codelyzer": "2.0.0-beta.1", "codelyzer": "2.0.0-beta.3",
"concurrently": "3.1.0", "concurrently": "3.1.0",
"cookie-parser": "1.4.3", "cookie-parser": "1.4.3",
"copy-webpack-plugin": "4.0.1", "copy-webpack-plugin": "4.0.1",
"imports-loader": "0.6.5", "imports-loader": "0.7.0",
"json-loader": "0.5.4", "json-loader": "0.5.4",
"node-sass": "3.13.0", "node-sass": "4.0.0",
"nodemon": "1.11.0", "nodemon": "1.11.0",
"raw-loader": "0.5.1", "raw-loader": "0.5.1",
"reflect-metadata": "0.1.8", "reflect-metadata": "0.1.8",
"rimraf": "2.5.4", "rimraf": "2.5.4",
"rollup": "0.37.0",
"rollup-plugin-commonjs": "6.0.0",
"rollup-plugin-node-globals": "1.1.0",
"rollup-plugin-node-resolve": "2.0.0",
"rollup-plugin-uglify": "1.0.1",
"string-replace-loader": "1.0.5", "string-replace-loader": "1.0.5",
"ts-helpers": "1.1.2", "ts-helpers": "1.1.2",
"ts-node": "1.7.0", "ts-node": "1.7.2",
"tslint": "4.0.2", "tslint": "4.0.2",
"tslint-loader": "3.3.0", "tslint-loader": "3.3.0",
"typedoc": "0.5.1", "typedoc": "0.5.1",
@@ -123,8 +132,8 @@
"v8-lazy-parse-webpack-plugin": "0.3.0", "v8-lazy-parse-webpack-plugin": "0.3.0",
"webpack": "2.1.0-beta.27", "webpack": "2.1.0-beta.27",
"webpack-bundle-analyzer": "1.4.1", "webpack-bundle-analyzer": "1.4.1",
"webpack-dev-middleware": "1.8.4", "webpack-dev-middleware": "1.9.0",
"webpack-dev-server": "2.1.0-beta.11", "webpack-dev-server": "2.1.0-beta.11",
"webpack-merge": "1.0.2" "webpack-merge": "1.1.1"
} }
} }

18
rollup-client.js Normal file
View File

@@ -0,0 +1,18 @@
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: 'dist/client/main.bundle.js',
dest: 'dist/client/build.js',
sourceMap: false,
format: 'iife',
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
}),
uglify()
]
}

18
rollup-server.js Normal file
View File

@@ -0,0 +1,18 @@
import rollup from 'rollup'
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify'
export default {
entry: 'dist/server/index.js',
dest: 'dist/server/build.js',
sourceMap: false,
format: 'iife',
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
}),
uglify()
]
}

20
src/index-aot.html Normal file
View File

@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>DSpace</title>
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<link rel="stylesheet" href="/styles/main.css">
<base href="/">
</head>
<body>
<ds-app>
Loading DSpace ...
</ds-app>
<script async src="/build.js"></script>
</body>
</html>

View File

@@ -79,7 +79,7 @@ app.get('/data.json', serverApi);
app.use('/api', createMockApi()); app.use('/api', createMockApi());
function ngApp(req, res) { function ngApp(req, res) {
res.render('index', { res.render('index-aot', {
req, req,
res, res,
// time: true, // use this to determine what part of your app is slow only in development // time: true, // use this to determine what part of your app is slow only in development

View File

@@ -1,15 +1,23 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"declaration": false, "declaration": false,
"removeComments": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"module": "commonjs", "allowUnreachableCode": false,
"moduleResolution": "node", "allowUnusedLabels": false,
"noEmitHelpers": true,
"noImplicitAny": false,
"noImplicitReturns": false,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"pretty": false,
"outDir": "dist", "outDir": "dist",
"sourceMap": true, "sourceMap": true,
"sourceRoot": "src", "sourceRoot": "src",
"noEmitHelpers": true,
"target": "es5",
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],
@@ -20,6 +28,7 @@
"./src/*.d.ts" "./src/*.d.ts"
], ],
"angularCompilerOptions": { "angularCompilerOptions": {
"skipMetadataEmit": true,
"debug": false "debug": false
}, },
"compileOnSave": false, "compileOnSave": false,

View File

@@ -1,15 +1,23 @@
{ {
"compilerOptions": { "compilerOptions": {
"declaration": false, "target": "es5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "node",
"declaration": false,
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noEmitHelpers": true,
"noImplicitAny": false,
"noImplicitReturns": false,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"pretty": true,
"outDir": "dist", "outDir": "dist",
"sourceMap": true, "sourceMap": true,
"sourceRoot": "src", "sourceRoot": "src",
"noEmitHelpers": true,
"target": "es5",
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
], ],

View File

@@ -12,10 +12,8 @@ export const commonPlugins = [
new V8LazyParseWebpackPlugin(), new V8LazyParseWebpackPlugin(),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { 'process.env.NODE_ENV': JSON.stringify('production'),
'NODE_ENV': JSON.stringify('production'), 'process.env.AOT': true
'AOT': true
}
}), }),
// Loader options // Loader options