summaryrefslogtreecommitdiffstats
path: root/catalog-ui/webpack.common.js
blob: 4482d0e0144711dc055a2884cee95ee56fbc31ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attr
const path = require('path');
const webpack = require('webpack');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const autoprefixer = require('autoprefixer');
const postcssUrl = require('postcss-url');
const {GlobCopyWebpackPlugin, BaseHrefWebpackPlugin} = require('@angular/cli/plugins/webpack');
const {CommonsChunkPlugin} = require('webpack').optimize;
const {AotPlugin} = require('@ngtools/webpack');
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const nodeModules = path.join(process.cwd(), 'node_modules');

const bundledScripts = [
    "script-loader!./node_modules/jquery/dist/jquery.min.js",
    "script-loader!./node_modules/lodash/lodash.min.js",
    "script-loader!./node_modules/angular/angular.min.js",
    "script-loader!./node_modules/restangular/dist/restangular.min.js",
    "script-loader!./node_modules/jqueryui/jquery-ui.min.js",
    "script-loader!./node_modules/angular-ui-router/release/angular-ui-router.min.js",
    "script-loader!./node_modules/angular-filter/dist/angular-filter.min.js",
    "script-loader!./node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js",
    "script-loader!./node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js",
    "script-loader!./node_modules/angular-resource/angular-resource.min.js",
    "script-loader!./node_modules/angular-base64/angular-base64.min.js",
    "script-loader!./node_modules/angular-uuid4/angular-uuid4.min.js",
    "script-loader!./node_modules/angular-translate/dist/angular-translate.min.js",
    "script-loader!./node_modules/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js",
    "script-loader!./node_modules/angular-base64-upload/dist/angular-base64-upload.min.js",
    "script-loader!./node_modules/angular-ui-notification/dist/angular-ui-notification.min.js",
    "script-loader!./node_modules/cytoscape/dist/cytoscape.min.js",
    "script-loader!./node_modules/checklist-model/checklist-model.js",
    "script-loader!./node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.min.js",
    "script-loader!./node_modules/qtip2/dist/jquery.qtip.min.js",
    "script-loader!./node_modules/@bardit/cytoscape-qtip/cytoscape-qtip.js",
    "script-loader!./node_modules/js-md5/build/md5.min.js",
    "script-loader!./node_modules/angular-clipboard/angular-clipboard.js",
    "script-loader!./node_modules/angular-resizable/angular-resizable.min.js",
    "script-loader!./node_modules/sdc-angular-dragdrop/src/angular-dragdrop.min.js",
    "script-loader!./node_modules/angular-tooltips/dist/angular-tooltips.min.js",
    "script-loader!./node_modules/angular-sanitize/angular-sanitize.min.js"
];
const baseHref = undefined;
const deployUrl = undefined;

// Arguments pass from webpack
const prod = process.argv.indexOf('-p') !== -1;

module.exports = function(params) {

    const webpackCommonConfig = {
        resolve: {
            extensions: [
                ".ts",
                ".js",
                ".less"
            ],
            modules: [
                "./node_modules"
            ],
            alias: {
                directives: path.join(__dirname, 'app/directives/'),
            }
        },
        resolveLoader: {
            modules: [
                "./node_modules"
            ]
        },
        entry: {
            'scripts/main': [ './src/main.ts' ],
            'scripts/polyfills': [ './src/polyfills.ts' ],
            'scripts/vendor': bundledScripts,
            'scripts/styles': [ "./src/styles.less" ]
        },
        module: {
            rules: [
                {
                    enforce: "pre",
                    test: /\.js$/,
                    loader: "source-map-loader",
                    exclude: [ /\/node_modules\// ]
                },
                { test: /\.json$/, loader: "json-loader" },
                { test: /\.html$/, loader: "html-loader" },
                {
                    exclude: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.css$/,
                    loaders: [
                        "exports-loader?module.exports.toString()",
                        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                        "postcss-loader"
                    ]
                },
                {
                    exclude: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.scss$|\.sass$/,
                    loaders: [
                        "exports-loader?module.exports.toString()",
                        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                        "postcss-loader",
                        "sass-loader"
                    ]
                },
                {
                    exclude: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.less$/,
                    loaders: [
                        "exports-loader?module.exports.toString()",
                        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                        "postcss-loader",
                        "less-loader"
                    ]
                },
                {
                    exclude: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.styl$/,
                    loaders: [
                        "exports-loader?module.exports.toString()",
                        "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                        "postcss-loader",
                        "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
                    ]
                },
                {
                    include: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.css$/,
                    loaders: ExtractTextPlugin.extract({
                        use: [
                            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                            "postcss-loader"
                        ],
                        fallback: "style-loader",
                        publicPath: ""
                    })
                },
                {
                    include: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.scss$|\.sass$/,
                    loaders: ExtractTextPlugin.extract({
                        use: [
                            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                            "postcss-loader",
                            "sass-loader"
                        ],
                        fallback: "style-loader",
                        publicPath: ""
                    })
                },
                {
                    include: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.less$/,
                    loaders: ExtractTextPlugin.extract({
                        use: [
                            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                            "postcss-loader",
                            "less-loader"
                        ],
                        fallback: "style-loader",
                        publicPath: ""
                    })
                },
                {
                    include: [ path.join(process.cwd(), "src/styles.less") ],
                    test: /\.styl$/,
                    loaders: ExtractTextPlugin.extract({
                        use: [
                            "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
                            "postcss-loader",
                            "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
                        ],
                        fallback: "style-loader",
                        publicPath: ""
                    })
                },
                { test: /\.ts$/, loader: "@ngtools/webpack" }
            ]
        },
        plugins: [
            new CleanWebpackPlugin(['dist', 'build'], {
                root: path.join(__dirname, ''),
                verbose: true,
                dry: false,
                exclude: ['shared.js']
            }),
            new webpack.LoaderOptionsPlugin({
                debug: false
            }),
            new webpack.DefinePlugin({
                process: {
                    env: {
                        sdcConfig: prod? '"production"': '"development"'
                    }
                }
            }),
            new webpack.NoEmitOnErrorsPlugin(),
            new ProgressPlugin(),
            // new BundleAnalyzerPlugin(),
            // new HtmlWebpackPlugin({
            //     template: "./src/index.html",
            //     filename: "./index.html",
            //     hash: false,
            //     inject: true,
            //     compile: true,
            //     favicon: false,
            //     minify: false,
            //     cache: true,
            //     showErrors: true,
            //     chunks: "all",
            //     excludeChunks: [],
            //     title: "Webpack App",
            //     xhtml: true,
            //     chunksSortMode: function sort(left, right) {
            //         let paramsString = params.entryPoints + '';
            //         let leftString = left.names[0].replace('scripts/','');
            //         let rightString = right.names[0].replace('scripts/','');
            //         let leftIndex = paramsString.indexOf(leftString);
            //         let rightindex = paramsString.indexOf(rightString);
            //         //console.log("left: " + leftString + " | leftIndex: " + leftIndex);
            //         //console.log("right: " + rightString + " | rightindex: " + rightindex);
            //         //console.log("result: " + leftIndex-rightindex);
            //         //console.log("----------------------------------------");
            //         return leftIndex-rightindex;
            //     }
            // }),
            new GlobCopyWebpackPlugin({
                patterns: [
                    "assets/languages",
                    "assets/styles/fonts",
                    "assets/styles/images",
                    "assets/styles/app.css"
                ],
                globOptions: {
                    cwd: path.join(process.cwd(), "src"),
                    dot: true,
                    ignore: "**/.gitkeep"
                }
            }),
            new GlobCopyWebpackPlugin({
                patterns: [
                    "configurations"
                ],
                globOptions: {
                    cwd: path.join(process.cwd(), ""),
                    dot: true,
                    ignore: "**/.gitkeep"
                }
            }),
            new BaseHrefWebpackPlugin({}),
            new CommonsChunkPlugin({
                name: "scripts/inline",
                minChunks: null
            }),
            new CommonsChunkPlugin({
                name: "scripts/vendor",
                minChunks: (module) => module.resource && module.resource.startsWith(nodeModules),
                chunks: [
                    "main"
                ]
            }),
            new ExtractTextPlugin({
                filename: "[name].bundle.css",
                disable: true
            }),
            new webpack.LoaderOptionsPlugin({
                sourceMap: false,
                options: {
                    postcss: [
                        autoprefixer(),
                        postcssUrl({
                            url: (URL) => {
                                // Only convert absolute URLs, which CSS-Loader won't process into require().
                                if (!URL.startsWith('/')) {
                                    return URL;
                                }
                                // Join together base-href, deploy-url and the original URL.
                                // Also dedupe multiple slashes into single ones.
                                return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
                            }
                        })
                    ],
                    sassLoader: {
                        sourceMap: false,
                        includePaths: []
                    },
                    lessLoader: {
                        sourceMap: false
                    },
                    context: ""
                }
            }),
            new AotPlugin({
                mainPath: "main.ts",
                exclude: [],
                tsConfigPath: "src/tsconfig.json",
                skipCodeGeneration: true
            })
        ],
        node: {
            fs: "empty",
            global: true,
            crypto: "empty",
            tls: "empty",
            net: "empty",
            process: true,
            module: false,
            clearImmediate: false,
            setImmediate: false
        }
    }

    return webpackCommonConfig;
}