Skip to content

Updated the gulp /build task to export both uglified and normal version - #532

Merged
nervgh merged 7 commits into
nervgh:masterfrom
andrei-cacio:feature/dist-contains-both-versions
Oct 27, 2015
Merged

nervgh merged 7 commits into
nervgh:masterfrom
andrei-cacio:feature/dist-contains-both-versions

Conversation

@andrei-cacio

Copy link
Copy Markdown
Contributor

This pull request fixes the #526 issue.

I've created 2 separate webpack streams and 2 separate gulp streams for both uglified and normal version of the file exported. A simple stream concat solved the problem and now there are both versions available in the dist folder.

@nervgh

nervgh commented Oct 20, 2015

Copy link
Copy Markdown
Owner

@andrei-cacio , thanks 👍 But I think more elegant way that. Then we and other developers can write something like this

gulp.task(
    pkg.name + '/build',
    function() {
        var MODULE = {
            loaders: [
                // https://github.com/babel/babel-loader
                {test: /\.js$/, loader: 'babel'},
                // https://github.com/webpack/json-loader
                {test: /\.json$/, loader: 'json'},
                // https://github.com/webpack/html-loader
                {test: /\.html$/, loader: 'html'}
            ]
        };
        // http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
        var UGLIFY = new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        });
        // http://webpack.github.io/docs/list-of-plugins.html#bannerplugin
        var BANNER = new webpack.BannerPlugin(
            '/*\n' +
            ' ' + pkg.name + ' v' + pkg.version + '\n' +
            ' ' + pkg.homepage + '\n' +
            '*/\n'
            ,
            {
                entryOnly: true,
                raw: true
            }
        );

        return gulp
            .src('./src/index.js')
            .pipe(webpackStream(
                [
                    // full
                    {
                        module: MODULE,
                        plugins: [BANNER],
                        devtool: 'source-map',
                        output: {
                            library: pkg.name,
                            libraryTarget: 'umd',
                            filename: pkg.name + '.js'
                        }
                    },
                    // min
                    {
                        module: MODULE,
                        plugins: [UGLIFY, BANNER],
                        devtool: 'source-map',
                        output: {
                            library: pkg.name,
                            libraryTarget: 'umd',
                            filename: pkg.name + '.min.js'
                        }
                    }
                ]
            ))
            .pipe(gulp.dest('./dist'));
    }
);

without additional dependencies. What is your opinon?

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

yes, I didn't thought of multiple web socket streams in a single array. Your version is definitely better. I will update my PR

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

hmm, although, it doesn't seem to work this way. It doesn't output anything.
Does webpack-stream support arrays as params? @nervgh

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

Looking into the webpack-stream package at the function exported, the options param is treated as an object (default {}). Am I missing something?

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

is this a good compromise? We only use the event-stream plugin to concat the new streams

gulp.task(
    pkg.name + '/build',
    function() {
        var MODULE = {
            loaders: [
                // https://github.com/babel/babel-loader
                {test: /\.js$/, loader: 'babel'},
                // https://github.com/webpack/json-loader
                {test: /\.json$/, loader: 'json'},
                // https://github.com/webpack/html-loader
                {test: /\.html$/, loader: 'html'}
            ]
        };
        // http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
        var UGLIFY = new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        });
        // http://webpack.github.io/docs/list-of-plugins.html#bannerplugin
        var BANNER = new webpack.BannerPlugin(
            '/*\n' +
            ' ' + pkg.name + ' v' + pkg.version + '\n' +
            ' ' + pkg.homepage + '\n' +
            '*/\n'
            ,
            {
                entryOnly: true,
                raw: true
            }
        );

        var normalStream =
            gulp
                .src('./src/index.js')
                .pipe(webpackStream({
                    module: MODULE,
                    plugins: [BANNER],
                    devtool: 'source-map',
                    output: {
                        library: pkg.name,
                        libraryTarget: 'umd',
                        filename: pkg.name + '.js'
                    }
                }))
                .pipe(gulp.dest('./dist'));

        var uglifyStream =
            gulp
                .src('./src/index.js')
                .pipe(webpackStream({
                    module: MODULE,
                    plugins: [BANNER, UGLIFY],
                    devtool: 'source-map',
                    output: {
                        library: pkg.name,
                        libraryTarget: 'umd',
                        filename: pkg.name + '.min.js'
                    }
                }))
                .pipe(gulp.dest('./dist'));

        return es.concat(normalStream, uglifyStream);
    }
);

@nervgh

@nervgh

nervgh commented Oct 21, 2015

Copy link
Copy Markdown
Owner

@andrei-cacio

But I think more elegant way that.
#532 (comment)

I did mean what If you have time and motivation for implementation of multi-compiler feature in the webpack-stream project then it will be great, otherwise I can merge your current PR.
First variant is prefered because we and other developers could be use it in other projects "out of the box".
Please, exclude dist/ files out of your PR if you will select second variant.

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

@nervgh

about the multi-compiler feature, I will try to open a PR for that but I cannot promise anything. Meanwhile if the actual PR version is ok with you, I'm fine for it to be merged. Should I remove both minified and normal files from the PR?

@nervgh

nervgh commented Oct 22, 2015

Copy link
Copy Markdown
Owner

Should I remove both minified and normal files from the PR?
#532 (comment)

Please, exclude dist/ files
#532 (comment)

dist/angular-file-upload.js
dist/angular-file-upload.js.map
dist/angular-file-upload.min.js
dist/angular-file-upload.min.js.map
  1. to format package.json with previous code style
@andrei-cacio

Copy link
Copy Markdown
Contributor Author

@nervgh I've reverted the dist folder and reverted the code style

@andrei-cacio

Copy link
Copy Markdown
Contributor Author

@nervgh also what do you think about #537 ?

nervgh added a commit that referenced this pull request Oct 27, 2015
…versions

Updated the gulp /build task to export both uglified and normal version
@nervgh
nervgh merged commit 9e1514e into nervgh:master Oct 27, 2015
@nervgh

nervgh commented Oct 27, 2015

Copy link
Copy Markdown
Owner

@andrei-cacio , good job, thanks! 👍

nervgh added a commit that referenced this pull request Oct 27, 2015
"Updated the gulp /build task to export both uglified and normal version" #532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants