webpack.config.js 6.67 KB
const path = require('path');
const jsdoc = require('jsdoc-webpack-plugin');
const copy = require('copy-webpack-plugin');
const eslint = require('eslint-webpack-plugin');

module.exports = [
    {
        name: "core",
        experiments : {
            outputModule: true
        },
        entry: { 
            'arcs' : {
                import : './src/exports.js',
            },
        },
        mode: 'none',
        output: {
            filename: '[name].js',
            path: path.resolve(__dirname, 'build'),
            library: {
                type: 'module',
            }
        },
        module: {
            parser: {
                javascript: {
                    commonjsMagicComments: true
                }
            }
        },
        plugins: [
            new eslint({}),
            new copy({
                patterns: [
                    { from :'src/arcs_browser.js', to: 'arcs_browser.js'},
                    { from: 'src/arcs_node.mjs', to: 'arcs_node.mjs'}
                ]
            })
        ]
    },
    {
        name: "core-min",
        experiments : {
            outputModule: true
        },
        entry: { 
            'arcs' : {
                import : './src/exports.js',
            },
        },
        mode: 'production',
        output: {
            filename: '[name].min.js',
            path: path.resolve(__dirname, 'build'),
            library: {
                type: 'module',
            }
        },
        module: {
            parser: {
                javascript: {
                    commonjsMagicComments: true
                }
            }
        },
    },
    {
        name: "doc",
        mode: "development",
        entry: {},
        plugins: [
            new jsdoc({
                conf: 'docs/engine.conf.json',
                destination:  'docs/engine',
                template: 'docs/arcs',            
            }),
            new jsdoc({
                conf: 'docs/components.conf.json',
                destination:  'docs/components',
                template: 'docs/arcs',            
            }),
        ]
    },
    {
        name: "deps",
        mode: "production",
        entry: {},
        plugins: [
            new copy({
                patterns: [
                    { from: 'node_modules/tracking/build/tracking.js', to: '../deps/tracking/tracking.js'},
                    { from: 'node_modules/three/build/three.module.js', to: '../deps/three.js/index.js'},
                    { 
                        from: 'node_modules/three/examples/jsm/loaders/OBJLoader.js', 
                        to: '../deps/objloader/index.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString().replace(
                                '../../../build/three.module.js',
                                '../three.js/index.js'
                            ));
                        }
                    },
                    { 
                        from: 'node_modules/three/examples/jsm/loaders/MTLLoader.js', 
                        to: '../deps/mtlloader/index.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString().replace(
                                '../../../build/three.module.js',
                                '../three.js/index.js'
                            ));
                        }
                    },
                    { 
                        from: 'node_modules/three/examples/jsm/loaders/DDSLoader.js', 
                        to: '../deps/ddsloader/index.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString().replace(
                                '../../../build/three.module.js',
                                '../three.js/index.js'
                            ));
                        }
                    },                
                    { 
                        from: 'node_modules/js-aruco/src/aruco.js',
                        to: '../deps/aruco/index.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString()
                                .replace(
                                    "var CV = require('./cv');",
                                    "import CV from '../cv/index.js';"                            
                                )
                                .replace(
                                    "module.exports = AR;",
                                    "export default AR;"
                                )
                            );
                        }
                    },
                    { 
                        from: 'node_modules/js-aruco/src/cv.js',
                        to: '../deps/cv/index.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString()
                                .replace(
                                    "module.exports = CV;",
                                    "export default CV;"
                                )
                            );
                        }
                    },
                    
                    
                    // TODO put here also files for dep directory.
                    // can also prepend content and replace strings using the transform property!
                ]            
            }),
        ]
    }
];



/*** parts of gruntfile not processed yet

    - minification with probably some custom targets

    files: { 
        'build/arcs.min.js': [
            'build/arcs.js'
        ],
        'build/arcs_browser.min.js': [
            'src/arcs_browser.js'
        ],
        'build/arcseditor.min.js': [
            'build/arcseditor.js'
        ]
    }
    
    - editor (to rebuild from scratch)
    
    editor : {
        src: [ 
                'utils/editor/arcseditor.js',
                'utils/editor/dragdrop.js',
                'utils/editor/template.js',
                'utils/editor/dialog.js',
                'utils/editor/componentdialog.js',
                'utils/editor/invocationdialog.js',
                'utils/editor/connectiondialog.js'
                ],
        dest: 'build/arcseditor.js'
    }    

***/

/*** parts of bower not processed yet
    not sure if it is of any use

    "codemirror" : "*",
    "CodeMirror-htmlmixed": "https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/htmlmixed/htmlmixed.js",
    "CodeMirror-javascript": "https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/javascript/javascript.js",
    "md5" :"*"

***/