W
W
Wasya UK2017-10-01 16:48:51
JavaScript
Wasya UK, 2017-10-01 16:48:51

How to run webpack config file written in ES6?

webpack.config.js

import Config, { enviroment } from 'webpack-config';

enviroment.setAll({
  env: () => process.env.NODE_ENV
});

export default new Config().extend('config/webpack.[env].config.js');

package.json
"devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-register": "^6.26.0",
    "html-webpack-plugin": "^2.30.1",
    "webpack": "^3.6.0",
    "webpack-config": "^7.4.0"
  },
  "scripts": {
    "build-dev": "set NODE_ENV=development && webpack --progress",
    "build-prod": "set NODE_ENV=production && webpack --progress"
  }

file structure:
webpack.config.js <-- (config/webpack.production.config.js || config/webpack.development.config.js) <-- config/webpack.base.config.js
they are all on ES6 I'm
running like this: npm run build- prod webpack.config.babel.js didn't help

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yura Komarov, 2019-06-21
@Yurajun

I found a solution.
I added the line

alias: {
        jquery: require.resolve('jquery'),
      },

in the webpack.config.js settings in the resolve section
Full description of the resolve block
resolve: {
      modulesDirectories: ['node_modules'],
      extensions: ['.js', ''],
      alias: {
        jquery: require.resolve('jquery'),
      },
    },

Now the parroller.js plugin is easily connected via import
However, in order to call it on the element, I had to wrap it in $(document).ready
import 'paroller.js';

$(document).ready(() => {
  $('.js-box').paroller({
    factor: 0.5,
    factorXs: 0.2,
    type: 'foreground',
    direction: 'horizontal',
  });
});

N
Negwereth, 2017-10-01
@Negwereth

The node does not know how to import yet. So either use modules that allow such code (and they exist), or use the usual require.

A
Anton, 2017-10-01
@SPAHI4

https://babeljs.io/docs/usage/babel-register/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question