Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const
- webpack = require('webpack'),
- uglify = require("uglify-js"),
- path = require('path'),
- fs = require('fs'),
- MemoryFS = require('memory-fs'),
- BASE_PATHS = {
- RESOURCES: 'src/main/webapp/resources/',
- CONTROLLERS: 'src/main/webapp/resources/js/controllers/',
- },
- WEBPACK_CONFIGURATION = {
- name: 'eonline-mobile',
- entry: {
- apps: path.join(__dirname, BASE_PATHS.CONTROLLERS + 'more/apps.js'),
- gallery: path.join(__dirname, BASE_PATHS.CONTROLLERS + 'photos/gallery.js')
- },
- output: {
- pathinfo: false,
- libraryTarget: 'umd',
- path: '/' /*path.join(__dirname, BASE_PATHS.RESOURCES, 'bundle')*/,
- filename: '[name].js'
- },
- devtool: 'source-map'
- };
- const mfs = new MemoryFS();
- /**
- * @type {Compiler}
- */
- const compiler = webpack(WEBPACK_CONFIGURATION);
- compiler.outputFileSystem = mfs;
- const filesInMemory = [];
- const FileById = function (name, data) {
- this.name = name;
- this.data = data;
- };
- compiler.run((error, stats) =>
- {
- console.log('webpack: bundle complete');
- console.assert((error == null), error);
- if (mfs.data) {
- Object.keys(mfs.data).forEach((item) => {
- if (item.indexOf('.map') === -1) {
- const content = mfs.readFileSync(path.join('/', item),'utf8');
- console.log('memory file sync complete for ', item);
- const ast = uglify.minify(
- {
- item: content
- },
- {
- fromString: true,
- warnings: false,
- mangleProperties: true,
- compress: {
- unsafe: true,
- collapse_vars: true,
- passes: 3,
- reduce_vars: true,
- join_vars: true,
- if_return: true,
- booleans: true
- }
- });
- console.log('uglify: compression complete for ', item);
- filesInMemory.push(new FileById(item, ast.code));
- }
- });
- }
- if (filesInMemory.length) {
- writeCodeToFile(0);
- }
- });
- function writeCodeToFile(index)
- {
- if (filesInMemory[index])
- {
- console.log('write file #', index+1);
- var fileInMemory = filesInMemory[index];
- fs.writeFile(fileInMemory.name, fileInMemory.data, null, () => {
- writeCodeToFile(index + 1);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement