How to import js files dynamically at compile time as input for browserify?
Ad
In our project structure we have a directory containing a number of js
files. We may add or remove any of these files later. Currently there is a main.js
in which we import each file and create a map (file name as the key and the class
defined in the file as the value).
Example:
Validator1.js
class Validator1 {
constructor() {
this.payRegex = /^[0-9][0-9][0-9]\/[A-Z,0-9][A-Z,0-9]*$/;
}
validate(obj) {
//do something
}
}
export default Validator1;
In main.js
import Validator1 from 'validator1.js';
import NoopValidator from './noop.js';
var validatorMap = {};
validatorMap['validator1'] = new Validator1;
validatorMap['DEFAULT'] = new NoopValidator;
We give this file to browserify to create a bundle.js
. Now as I said there are a number of files in that folder and we want to generate this file at compile time with maven.
- Is there any way other than creating a maven plugin to do this?
- We are using EMAScript6
Ad
Answer
Ad
There isn't a built-in way to do this, but a Browserify Transform could handle the task. You could write one yourself, but I think Bulkify might do what you want already, depending on what format you want the result in.
See:
Ad
source: stackoverflow.com
Related Questions
Ad
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad