How to add a local JavaScript file to Webpack?

Viewed 526

I'm trying to convert a project to use Webpack, and I have a script.js file that has some jQuery scripts running and some functions inside it.

In the index.js file I import script.js and build webpack.

import $ from 'jquery'; // from CDN
import 'bootstrap';
import '../js/script.js';

If I look in bundle.js i can see all the code from script.js in there, except that I can't use any of them.. getting random undefined functions when trying to call any of them by using inline js.

any ideas?

webpack config file

const path    = require('path');
const webpack = require('webpack');

module.exports = {
    entry    : {
        app: './public/src/index.js'
    },
    output   : {
        filename: 'bundle.js',
        path    : path.resolve(__dirname, 'public/dist')
    },
    plugins  : [
        new webpack.ProvidePlugin({
            $              : 'jquery',
            jQuery         : 'jquery',
            'window.jQuery': 'jquery',
            Popper         : ['popper.js', 'default'],
        })
    ],
    externals: {
        jquery: 'jQuery'
    },
    module   : {
        loaders: [
            {
                test  : /datatables\.net.*/,
                loader: 'imports?define=>false'
            }
        ],
        rules  : [
            {
                test: /\.css$/,
                use : [
                    'style-loader',
                    'css-loader'
                ]
            }
        ]
    }
};
0 Answers
Related