Fix #55 , and also added functionality for scripts global building

This commit is contained in:
Theophilus Omorebee
2017-09-14 12:58:16 +01:00
parent 2ac2aa0abc
commit 012a894c04
3 changed files with 12034 additions and 550 deletions

View File

@@ -5,9 +5,10 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const postcssUrl = require('postcss-url');
const ConcatPlugin = require('webpack-concat-plugin');
const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin, DefinePlugin, HashedModuleIdsPlugin } = require('webpack');
const { GlobCopyWebpackPlugin, BaseHrefWebpackPlugin } = require('@angular/cli/plugins/webpack');
const { GlobCopyWebpackPlugin, BaseHrefWebpackPlugin, InsertConcatAssetsWebpackPlugin } = require('@angular/cli/plugins/webpack');
const { CommonsChunkPlugin, UglifyJsPlugin } = require('webpack').optimize;
const { AotPlugin } = require('@ngtools/webpack');
@@ -18,6 +19,19 @@ const deployUrl = "";
const isProd = (process.env.NODE_ENV === 'production');
//add all external css to be added in our index.html--> like as if it's .angular-cli.json
const styles = [
"./src/assets/css/bootstrap.css",
"./src/styles.scss"
];
//we add all our external scripts we want to load externally, like inserting in our index.html --> like as if it's .angular-cli.json
const scripts = [
];
//create file path for each , so we use for our excludes and includes where needed
let style_paths = styles.map(style_src => path.join(process.cwd(), style_src));
function getPlugins() {
var plugins = [];
@@ -30,6 +44,19 @@ function getPlugins() {
plugins.push(new NoEmitOnErrorsPlugin());
if(scripts.length > 0){
plugins.push(new ConcatPlugin({
"uglify": false,
"sourceMap": true,
"name": "scripts",
"fileName": "[name].bundle.js",
"filesToConcat": scripts
}));
plugins.push(new InsertConcatAssetsWebpackPlugin([
"scripts"
]));
}
plugins.push(new GlobCopyWebpackPlugin({
"patterns": [
"assets",
@@ -225,9 +252,7 @@ module.exports = {
"polyfills": [
"./src/polyfills.ts"
],
"styles": [
"./src/styles.scss"
]
"styles": styles
},
"output": {
"path": path.join(process.cwd(), "dist"),
@@ -258,9 +283,7 @@ module.exports = {
"loader": "url-loader?name=[name].[hash:20].[ext]&limit=10000"
},
{
"exclude": [
path.join(process.cwd(), "src/styles.scss")
],
"exclude": style_paths,
"test": /\.css$/,
"loaders": [
"exports-loader?module.exports.toString()",
@@ -269,9 +292,7 @@ module.exports = {
]
},
{
"exclude": [
path.join(process.cwd(), "src/styles.scss")
],
"exclude": style_paths,
"test": /\.scss$|\.sass$/,
"loaders": [
"exports-loader?module.exports.toString()",
@@ -281,9 +302,7 @@ module.exports = {
]
},
{
"exclude": [
path.join(process.cwd(), "src/styles.scss")
],
"exclude": style_paths,
"test": /\.less$/,
"loaders": [
"exports-loader?module.exports.toString()",
@@ -293,9 +312,7 @@ module.exports = {
]
},
{
"exclude": [
path.join(process.cwd(), "src/styles.scss")
],
"exclude": style_paths,
"test": /\.styl$/,
"loaders": [
"exports-loader?module.exports.toString()",
@@ -305,9 +322,7 @@ module.exports = {
]
},
{
"include": [
path.join(process.cwd(), "src/styles.scss")
],
"include": style_paths,
"test": /\.css$/,
"loaders": ExtractTextPlugin.extract({
"use": [
@@ -319,9 +334,7 @@ module.exports = {
})
},
{
"include": [
path.join(process.cwd(), "src/styles.scss")
],
"include": style_paths,
"test": /\.scss$|\.sass$/,
"loaders": ExtractTextPlugin.extract({
"use": [
@@ -334,9 +347,7 @@ module.exports = {
})
},
{
"include": [
path.join(process.cwd(), "src/styles.scss")
],
"include":style_paths,
"test": /\.less$/,
"loaders": ExtractTextPlugin.extract({
"use": [
@@ -349,9 +360,7 @@ module.exports = {
})
},
{
"include": [
path.join(process.cwd(), "src/styles.scss")
],
"include": style_paths,
"test": /\.styl$/,
"loaders": ExtractTextPlugin.extract({
"use": [