Skip to content

Commit

Permalink
Merge pull request #1 from viettrannetc/dev-fake-be
Browse files Browse the repository at this point in the history
Dev fake be
  • Loading branch information
sstglobal authored May 16, 2019
2 parents f0aacb6 + 6a785ed commit 0b44d68
Show file tree
Hide file tree
Showing 55 changed files with 20,576 additions and 4,750 deletions.
10 changes: 10 additions & 0 deletions bs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

module.exports = {
server: {
baseDir: './dist',
middleware: {
1: require('connect-history-api-fallback')({ index: '/index.html', verbose: true })
}
}
};
13 changes: 13 additions & 0 deletions config/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const path = require('path');

const _root = path.resolve(__dirname, '..');

function root(args) {
args = Array.prototype.slice.call(arguments, 0);

return path.join.apply(path, [_root].concat(args));
}

exports.root = root;
73 changes: 73 additions & 0 deletions config/webpack.config.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const helpers = require('./helpers');
const isDev = process.env.NODE_ENV !== 'production';

module.exports = {
entry: {
vendor: './src/vendor.ts',
polyfills: './src/polyfills.ts',
main: isDev ? './src/main.ts' : './src/main.aot.ts'
},

resolve: {
extensions: ['.ts', '.js', '.scss']
},

module: {
rules: [{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(scss|sass)$/,
use: [
{ loader: 'style-loader', options: { sourceMap: isDev } },
{ loader: 'css-loader', options: { sourceMap: isDev } },
{ loader: 'sass-loader', options: { sourceMap: isDev } }
],
include: helpers.root('src', 'assets')
},
{
test: /\.(scss|sass)$/,
use: [
'to-string-loader',
{ loader: 'css-loader', options: { sourceMap: isDev } },
{ loader: 'sass-loader', options: { sourceMap: isDev } }
],
include: helpers.root('src', 'app')
}
]
},

plugins: [
new CleanWebpackPlugin(
helpers.root('dist'), { root: helpers.root(), verbose: true }),

new HtmlWebpackPlugin({
template: 'src/index.html'
}),

new CopyWebpackPlugin([
{ from: 'src/assets', to: 'assets' }
]),

new webpack.DefinePlugin({
// global app config object
config: JSON.stringify({
apiUrl: isDev ? 'https://localhost:44301' : 'https://wa-tlvn.azurewebsites.net',
})
})
]
};
43 changes: 43 additions & 0 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const webpackMerge = require('webpack-merge');
const commonConfig = require('./webpack.config.common');
const helpers = require('./helpers');

module.exports = webpackMerge(commonConfig, {
mode: 'development',

devtool: 'cheap-module-eval-source-map',

output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
},

optimization: {
noEmitOnErrors: true
},

module: {
rules: [{
test: /\.ts$/,
loaders: [{
loader: 'awesome-typescript-loader',
options: {
configFileName: helpers.root('tsconfig.json')
}
},
'angular2-template-loader',
'angular-router-loader',
],
exclude: [/node_modules/],
}]
},

devServer: {
historyApiFallback: true,
stats: 'minimal',
}
});
59 changes: 59 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const webpackMerge = require('webpack-merge');
const ngw = require('@ngtools/webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const cssnano = require('cssnano');

const commonConfig = require('./webpack.config.common');
const helpers = require('./helpers');

module.exports = webpackMerge(commonConfig, {
mode: 'production',

output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[hash].js',
chunkFilename: '[id].[hash].chunk.js',
},

optimization: {
noEmitOnErrors: true,
splitChunks: {
chunks: 'all'
},
runtimeChunk: 'single',
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
}),

new OptimizeCSSAssetsPlugin({
cssProcessor: cssnano,
cssProcessorOptions: {
discardComments: {
removeAll: true
}
},
canPrint: false,
}),
]
},

module: {
rules: [{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack',
}, ],
},

plugins: [
new ngw.AngularCompilerPlugin({
tsConfigPath: helpers.root('tsconfig.aot.json'),
entryModule: helpers.root('src', 'app', 'app.module#AppModule'),
}),
],
});
Loading

0 comments on commit 0b44d68

Please sign in to comment.