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

module.exports = [
    {
        name: "doc",
        mode: "development",
        entry: {},
        plugins: [
            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/arcsjs/build/arcs.js', to: '../engine/arcs.js'},
                    { from: 'node_modules/jsqr/dist/jsQR.js', to: '../deps/jsqr/jsQR.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/three/examples/jsm/webxr/ARButton.js', 
                        to: '../deps/three.js/ARButton.js',
                        transform: function(content, path) {
                            return Buffer.from(content.toString().replace(
                                '../../../build/three.module.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!
                ]            
            }),
        ]
    }
];