From 7f5b399a0f6fcf84ba84313f7ce184714d867a4f Mon Sep 17 00:00:00 2001 From: orizens Date: Sun, 16 Oct 2016 17:54:01 +0300 Subject: [PATCH] cleanup for webpack, reorganize config --- .eslintrc.json | 3 +- {gulp => config}/config/config.protractor.js | 0 {gulp => config}/config/protractor.conf.bs.js | 0 {gulp => config}/deploy.sh | 2 +- {gulp => config}/dist-assets/CNAME | 0 {gulp => config}/dist-assets/manifest.json | 0 {gulp => config}/dogen.js | 0 {gulp => config}/e2e-test.js | 0 {gulp => config}/prod-serve.json | 0 .../_ngmodule_/_ngmodule_.component.js | 0 .../_ngmodule_/_ngmodule_.component.spec.js | 0 .../templates/_ngmodule_/_ngmodule_.less | 0 .../templates/_ngmodule_/_ngmodule_.tpl.html | 0 .../templates/_ngmodule_/index.js | 0 .../templates/_ngservice_/_ngservice_.srv.js | 0 gulp/server.js | 27 --- gulpfile.babel.js | 25 +-- karma.conf.js | 2 +- package.json | 9 +- rollup.config.js | 14 -- .../{dev.config.js => development.config.js} | 0 webpack.common.js | 91 ++++++++++ webpack.config.js | 160 +++++++++--------- webpack.config.production.js | 156 +++++++++-------- 24 files changed, 265 insertions(+), 224 deletions(-) rename {gulp => config}/config/config.protractor.js (100%) rename {gulp => config}/config/protractor.conf.bs.js (100%) rename {gulp => config}/deploy.sh (94%) rename {gulp => config}/dist-assets/CNAME (100%) rename {gulp => config}/dist-assets/manifest.json (100%) rename {gulp => config}/dogen.js (100%) rename {gulp => config}/e2e-test.js (100%) rename {gulp => config}/prod-serve.json (100%) rename {gulp => config}/templates/_ngmodule_/_ngmodule_.component.js (100%) rename {gulp => config}/templates/_ngmodule_/_ngmodule_.component.spec.js (100%) rename {gulp => config}/templates/_ngmodule_/_ngmodule_.less (100%) rename {gulp => config}/templates/_ngmodule_/_ngmodule_.tpl.html (100%) rename {gulp => config}/templates/_ngmodule_/index.js (100%) rename {gulp => config}/templates/_ngservice_/_ngservice_.srv.js (100%) delete mode 100644 gulp/server.js delete mode 100644 rollup.config.js rename src/config/{dev.config.js => development.config.js} (100%) create mode 100644 webpack.common.js diff --git a/.eslintrc.json b/.eslintrc.json index 4b94470..523081b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -38,7 +38,8 @@ "angular": true, "inject": true, "__dirname": true, - "gapi": true + "gapi": true, + "process": true }, "extends": "eslint:recommended" } diff --git a/gulp/config/config.protractor.js b/config/config/config.protractor.js similarity index 100% rename from gulp/config/config.protractor.js rename to config/config/config.protractor.js diff --git a/gulp/config/protractor.conf.bs.js b/config/config/protractor.conf.bs.js similarity index 100% rename from gulp/config/protractor.conf.bs.js rename to config/config/protractor.conf.bs.js diff --git a/gulp/deploy.sh b/config/deploy.sh similarity index 94% rename from gulp/deploy.sh rename to config/deploy.sh index 6fef329..647b316 100755 --- a/gulp/deploy.sh +++ b/config/deploy.sh @@ -2,7 +2,7 @@ if [ "$TRAVIS_BRANCH" == "master" ]; then git config --global user.email "farhioren+travis@gmail.com" git config --global user.name "travis-ci" - npm run release + npm run prod cd dist git init git add . diff --git a/gulp/dist-assets/CNAME b/config/dist-assets/CNAME similarity index 100% rename from gulp/dist-assets/CNAME rename to config/dist-assets/CNAME diff --git a/gulp/dist-assets/manifest.json b/config/dist-assets/manifest.json similarity index 100% rename from gulp/dist-assets/manifest.json rename to config/dist-assets/manifest.json diff --git a/gulp/dogen.js b/config/dogen.js similarity index 100% rename from gulp/dogen.js rename to config/dogen.js diff --git a/gulp/e2e-test.js b/config/e2e-test.js similarity index 100% rename from gulp/e2e-test.js rename to config/e2e-test.js diff --git a/gulp/prod-serve.json b/config/prod-serve.json similarity index 100% rename from gulp/prod-serve.json rename to config/prod-serve.json diff --git a/gulp/templates/_ngmodule_/_ngmodule_.component.js b/config/templates/_ngmodule_/_ngmodule_.component.js similarity index 100% rename from gulp/templates/_ngmodule_/_ngmodule_.component.js rename to config/templates/_ngmodule_/_ngmodule_.component.js diff --git a/gulp/templates/_ngmodule_/_ngmodule_.component.spec.js b/config/templates/_ngmodule_/_ngmodule_.component.spec.js similarity index 100% rename from gulp/templates/_ngmodule_/_ngmodule_.component.spec.js rename to config/templates/_ngmodule_/_ngmodule_.component.spec.js diff --git a/gulp/templates/_ngmodule_/_ngmodule_.less b/config/templates/_ngmodule_/_ngmodule_.less similarity index 100% rename from gulp/templates/_ngmodule_/_ngmodule_.less rename to config/templates/_ngmodule_/_ngmodule_.less diff --git a/gulp/templates/_ngmodule_/_ngmodule_.tpl.html b/config/templates/_ngmodule_/_ngmodule_.tpl.html similarity index 100% rename from gulp/templates/_ngmodule_/_ngmodule_.tpl.html rename to config/templates/_ngmodule_/_ngmodule_.tpl.html diff --git a/gulp/templates/_ngmodule_/index.js b/config/templates/_ngmodule_/index.js similarity index 100% rename from gulp/templates/_ngmodule_/index.js rename to config/templates/_ngmodule_/index.js diff --git a/gulp/templates/_ngservice_/_ngservice_.srv.js b/config/templates/_ngservice_/_ngservice_.srv.js similarity index 100% rename from gulp/templates/_ngservice_/_ngservice_.srv.js rename to config/templates/_ngservice_/_ngservice_.srv.js diff --git a/gulp/server.js b/gulp/server.js deleted file mode 100644 index 19c110f..0000000 --- a/gulp/server.js +++ /dev/null @@ -1,27 +0,0 @@ -import gulp from 'gulp'; -import webserver from 'gulp-webserver'; - -gulp.task('webserver', () => { - gulp.src([ - 'src', - '.tmp' - ]) - .pipe(webserver({ - livereload: true, - // directoryListing: true, - // open: true, - port: 9001 - })); -}); - -gulp.task('server:dist', () => { - gulp.src([ - 'dist' - ]) - .pipe(webserver({ - livereload: true, - // directoryListing: true, - // open: true, - port: 9002 - })); -}); \ No newline at end of file diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 7f7e881..e078150 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,26 +1,3 @@ import gulp from 'gulp'; -import runSequence from 'run-sequence'; -// require external tasks -// import './gulp/assets.js'; -// import './gulp/server.js'; -import './gulp/test.js'; -// import './gulp/watch.js'; -// import './gulp/style.js'; -// import './gulp/dist.js'; -// import './gulp/e2e-test.js'; -// import './gulp/browserify.js'; -// import './gulp/dogen.js'; - -gulp.task('default', ['serve']); -gulp.task('serve', (callback) => { - runSequence( - // 'build', - 'style', - 'assets', - // 'build:vendors', - // 'browserify', - 'watch' - // 'webserver' - ); -}); \ No newline at end of file +import './config/dogen.js'; \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index f921000..9d58197 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -47,7 +47,7 @@ const options = { }] }, plugins: [ - new ExtractTextPlugin('[name].[chunkhash].style.css'), + new ExtractTextPlugin('[name].[chunkhash].style.css') ], resolve: {} }, diff --git a/package.json b/package.json index 7ad2481..2997f3a 100644 --- a/package.json +++ b/package.json @@ -8,16 +8,15 @@ "pioneer": "node_modules/pioneer/bin/pioneer", "e2e": "protractor protractor.conf.js", "e2ed": "protractor debug protractor.conf.js", - "e2e:remote": "protractor ./gulp/config/protractor.conf.bs.js", + "e2e:remote": "protractor ./config/config/protractor.conf.bs.js", "test": "NODE_ENV='test' karma start", "testd": "DEBUG=true npm test", "bdd": "NODE_ENV='test' BDD=true npm test", - "start": "NODE_ENV='dev' npm run dev", - "build": "gulp build && gulp build:vendors && gulp style", + "start": "NODE_ENV='development' npm run dev", "wpw": "webpack -d --watch", "dev": "webpack-dev-server --hot --inline --progress --colors --content-base src --port 9001", - "release": "rimraf dist/ && webpack --config=webpack.config.production.js -p", - "prod:serve": "lite-server -c gulp/prod-serve.json" + "prod": "rimraf dist/ && NODE_ENV='production' webpack --config=webpack.config.production.js -p", + "prod:serve": "lite-server -c config/prod-serve.json" }, "repository": { "type": "git", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index e3d5613..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,14 +0,0 @@ -import babel from 'rollup-plugin-babel'; -import string from 'rollup-plugin-string'; - -export default { - entry: 'src/app.js', - format: 'cjs', - plugins: [ - string({ - extensions: ['.html'] - }), - babel() - ], - dest: '.tmp/bundle-roll.js' -}; \ No newline at end of file diff --git a/src/config/dev.config.js b/src/config/development.config.js similarity index 100% rename from src/config/dev.config.js rename to src/config/development.config.js diff --git a/webpack.common.js b/webpack.common.js new file mode 100644 index 0000000..7521cf0 --- /dev/null +++ b/webpack.common.js @@ -0,0 +1,91 @@ +const path = require('path'); +const webpack = require('webpack'); +// const ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const getPath = (pathToFile) => path.resolve(__dirname, pathToFile); +const env = process.env.NODE_ENV || 'development'; +// const envConfig = require('./config/environment/' + env + '.env'); +const APP_NAME = 'echoes'; + +module.exports = { + entry: { + app: [ + getPath('./src/app.js'), + getPath('./src/config/' + env + '.config.js') + ], + vendors: [ + 'angular', + 'angular-ui-router', + 'angular-animate', + 'angular-sanitize', + 'angular-ui-bootstrap', + 'angular-local-storage' + ] + }, + output: { + path: getPath('./dist'), + filename: '[name].[hash].bundle.js' + }, + module: { + loaders: [{ + test: /\.js$/, + exclude: /(node_modules)/, + loaders: ['babel'] + }, { + test: /\.html$/, + loader: 'ngtemplate!html', + exclude: /(index)/ + }, { + test: /\.less$/, + loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap') + }, + // FONTS + { + test: /\.woff$/, + loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' + }, { + test: /\.eot$/, + loader: 'file' + }, { + test: /\.svg$/, + loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' + }, + // the url-loader uses DataUrls. + // the file-loader emits files. + { + test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, + loader: 'url?limit=10000&minetype=application/font-woff' + }, { + test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, + loader: 'file' + }] + }, + + plugins: [ + new webpack.DefinePlugin({ + 'NODE_ENV': JSON.stringify(process.env.NODE_ENV), + 'APP_NAME': JSON.stringify(APP_NAME) + }), + // new webpack.DefinePlugin({ + // 'APP_ENV': JSON.stringify(envConfig) + // }), + new webpack.optimize.CommonsChunkPlugin('vendors', + '[name].[hash].js'), + new webpack.optimize.AggressiveMergingPlugin({}), + new webpack.optimize.OccurenceOrderPlugin(true), + new ExtractTextPlugin('[name].[hash].style.css'), + // HtmlWebpackPlugin + // See: https://github.com/ampedandwired/html-webpack-plugin + new HtmlWebpackPlugin({ + template: 'html!./src/index.html' + }), + new CopyWebpackPlugin([ + { + from: 'src/assets', + to: 'assets' + } + ]) + ] +}; diff --git a/webpack.config.js b/webpack.config.js index 1765a40..97e2ab6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,82 +1,80 @@ -const path = require('path'); -const webpack = require('webpack'); -const ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const ExtractTextPlugin = require('extract-text-webpack-plugin'); - -const getPath = (pathToFile) => path.resolve(__dirname, pathToFile); - -module.exports = { - devtool: 'eval-source-map', - entry: { - app: [ - getPath('./src/app.js'), - getPath('./src/config/dev.config.js') - ], - vendors: [ - 'angular', - 'angular-ui-router', - 'angular-animate', - 'angular-sanitize', - 'angular-ui-bootstrap', - 'angular-local-storage' - ] - }, - output: { - path: getPath('./dist'), - filename: '[name].[chunkhash].bundle.js', - sourceMapFilename: '[name].[chunkhash].bundle.map' - }, - module: { - loaders: [{ - test: /\.js$/, - exclude: /(node_modules)/, - loaders: ['babel'] - }, { - test: /\.html$/, - loader: 'ngtemplate!html', - exclude: /(index)/ - }, { - test: /\.less$/, - loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap') - }, - // FONTS - { - test: /\.woff$/, - loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' - }, { - test: /\.eot$/, - loader: 'file' - }, { - test: /\.svg$/, - loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' - }, - // the url-loader uses DataUrls. - // the file-loader emits files. - { - test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, - loader: 'url?limit=10000&minetype=application/font-woff' - }, { - test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, - loader: 'file' - }] - }, - - plugins: [ - new webpack.DefinePlugin({ - 'NODE_ENV': JSON.stringify(process.env.NODE_ENV) - }), - new ngAnnotatePlugin({ - add: true - // other ng-annotate options here - }), - new webpack.optimize.CommonsChunkPlugin('vendors', - 'vendors.[hash].js'), - new ExtractTextPlugin('[name].[chunkhash].style.css'), - // HtmlWebpackPlugin - // See: https://github.com/ampedandwired/html-webpack-plugin - new HtmlWebpackPlugin({ - template: 'html!./src/index.html' - }) - ] +var webpackCommon = require('./webpack.common'); +var webpackConfig = { + devtool: 'eval-source-map' }; +webpackCommon.devtool = webpackConfig.devtool; +module.exports = webpackCommon; +// module.exports = { +// devtool: 'eval-source-map', +// entry: { +// app: [ +// getPath('./src/app.js'), +// getPath('./src/config/dev.config.js') +// ], +// vendors: [ +// 'angular', +// 'angular-ui-router', +// 'angular-animate', +// 'angular-sanitize', +// 'angular-ui-bootstrap', +// 'angular-local-storage' +// ] +// }, +// output: { +// path: getPath('./dist'), +// filename: '[name].[chunkhash].bundle.js', +// sourceMapFilename: '[name].[chunkhash].bundle.map' +// }, +// module: { +// loaders: [{ +// test: /\.js$/, +// exclude: /(node_modules)/, +// loaders: ['babel'] +// }, { +// test: /\.html$/, +// loader: 'ngtemplate!html', +// exclude: /(index)/ +// }, { +// test: /\.less$/, +// loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap') +// }, +// // FONTS +// { +// test: /\.woff$/, +// loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' +// }, { +// test: /\.eot$/, +// loader: 'file' +// }, { +// test: /\.svg$/, +// loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' +// }, +// // the url-loader uses DataUrls. +// // the file-loader emits files. +// { +// test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, +// loader: 'url?limit=10000&minetype=application/font-woff' +// }, { +// test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, +// loader: 'file' +// }] +// }, + +// plugins: [ +// new webpack.DefinePlugin({ +// 'NODE_ENV': JSON.stringify(process.env.NODE_ENV) +// }), +// new ngAnnotatePlugin({ +// add: true +// // other ng-annotate options here +// }), +// new webpack.optimize.CommonsChunkPlugin('vendors', +// 'vendors.[hash].js'), +// new ExtractTextPlugin('[name].[chunkhash].style.css'), +// // HtmlWebpackPlugin +// // See: https://github.com/ampedandwired/html-webpack-plugin +// new HtmlWebpackPlugin({ +// template: 'html!./src/index.html' +// }) +// ] +// }; diff --git a/webpack.config.production.js b/webpack.config.production.js index 7d79971..0bf7c10 100644 --- a/webpack.config.production.js +++ b/webpack.config.production.js @@ -1,84 +1,100 @@ -const path = require('path'); -const webpack = require('webpack'); const ngAnnotatePlugin = require('ng-annotate-webpack-plugin'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const ExtractTextPlugin = require('extract-text-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); -const getPath = (pathToFile) => path.resolve(__dirname, pathToFile); -module.exports = { - devtool: 'source-map', - entry: { - app: [ - getPath('./src/app.js'), - getPath('./src/config/production.config.js') - ], - vendors: [ - 'angular', - 'angular-ui-router', - 'angular-animate', - 'angular-sanitize', - 'angular-ui-bootstrap', - 'angular-local-storage' - ] - }, - output: { - path: getPath('./dist'), - filename: '[name].[chunkhash].bundle.js' - }, - module: { - loaders: [{ - test: /\.js$/, - exclude: /(node_modules)/, - loaders: ['babel'] - }, { - test: /\.html$/, - loader: 'ngtemplate!html', - exclude: /(index)/ - }, { - test: /\.less$/, - loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap') - }, - // FONTS - { - test: /\.woff$/, - loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' - }, { - test: /\.eot$/, - loader: 'file' - }, { - test: /\.svg$/, - loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' - }, - // the url-loader uses DataUrls. - // the file-loader emits files. - { - test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, - loader: 'url?limit=10000&minetype=application/font-woff' - }, { - test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, - loader: 'file' - } - ]}, +var webpackCommon = require('./webpack.common'); +var webpackConfig = { + devtool: 'cheap-source-map', plugins: [ new ngAnnotatePlugin({ add: true - // other ng-annotate options here - }), - new webpack.optimize.CommonsChunkPlugin('vendors', - '[name].[chunkhash].vendors.js'), - new ExtractTextPlugin('[name].[chunkhash].style.css'), - // See: https://github.com/ampedandwired/html-webpack-plugin - new HtmlWebpackPlugin({ - template: 'html!./src/index.html' }), new CopyWebpackPlugin([{ - from: 'gulp/dist-assets/CNAME' + from: 'config/dist-assets/CNAME' }, { - from: 'gulp/dist-assets/manifest.json' + from: 'config/dist-assets/manifest.json' }, { from: 'src/assets', to: 'assets' }]) ] -}; \ No newline at end of file +}; +webpackCommon.devtool = webpackConfig.devtool; +webpackCommon.plugins = webpackCommon.plugins.concat(webpackConfig.plugins); +module.exports = webpackCommon; + +// module.exports = { +// devtool: 'source-map', +// entry: { +// app: [ +// getPath('./src/app.js'), +// getPath('./src/config/production.config.js') +// ], +// vendors: [ +// 'angular', +// 'angular-ui-router', +// 'angular-animate', +// 'angular-sanitize', +// 'angular-ui-bootstrap', +// 'angular-local-storage' +// ] +// }, +// output: { +// path: getPath('./dist'), +// filename: '[name].[chunkhash].bundle.js' +// }, +// module: { +// loaders: [{ +// test: /\.js$/, +// exclude: /(node_modules)/, +// loaders: ['babel'] +// }, { +// test: /\.html$/, +// loader: 'ngtemplate!html', +// exclude: /(index)/ +// }, { +// test: /\.less$/, +// loader: ExtractTextPlugin.extract('css?sourceMap!less?sourceMap') +// }, +// // FONTS +// { +// test: /\.woff$/, +// loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' +// }, { +// test: /\.eot$/, +// loader: 'file' +// }, { +// test: /\.svg$/, +// loader: 'url?limit=100000&name=./fonts/[name]/[hash].[ext]' +// }, +// // the url-loader uses DataUrls. +// // the file-loader emits files. +// { +// test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, +// loader: 'url?limit=10000&minetype=application/font-woff' +// }, { +// test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, +// loader: 'file' +// } +// ]}, +// plugins: [ +// new ngAnnotatePlugin({ +// add: true +// // other ng-annotate options here +// }), +// new webpack.optimize.CommonsChunkPlugin('vendors', +// '[name].[chunkhash].vendors.js'), +// new ExtractTextPlugin('[name].[chunkhash].style.css'), +// // See: https://github.com/ampedandwired/html-webpack-plugin +// new HtmlWebpackPlugin({ +// template: 'html!./src/index.html' +// }), +// new CopyWebpackPlugin([{ +// from: 'config/dist-assets/CNAME' +// }, { +// from: 'config/dist-assets/manifest.json' +// }, { +// from: 'src/assets', +// to: 'assets' +// }]) +// ] +// }; \ No newline at end of file