简体   繁体   中英

how to include frontend javascript files to bundle webpack

I need to bundle my front-end javascript files to bundle.js. here is my webpack.config file,

var path = require('path');
var nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    target: 'node',
    entry:['babel-polyfill', './bin/run.js'],
    output: {
        path: './build',
        filename: '[name].min.js'
    },
    externals: nodeModules,
    plugins: [
        new HtmlWebpackPlugin(),
        new webpack.optimize.UglifyJsPlugin({
            compressor: {
                warnings: false,
                screw_ie8: true
            }
        })
    ],
    module: {
        loaders: [
            {
                loader: 'babel-loader',
                test: /\.js$/,
                include:/public/,
                exclude: /(node_modules|bower_components)/
            }
        ],
        noParse: [/ws/]
    }
};

how can I include my front-end javascript files to the bundle ?

If you are using webpack2 then you should know this change:

module: {
    rules: [ // <----it is been changed to "rules"
        {
            test: /\.js$/,
            loader: 'babel-loader',
            exclude: /(node_modules|bower_components)/
        }
    ],
    noParse: [/ws/]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM