【问题标题】:how to include frontend javascript files to bundle webpack如何包含前端 javascript 文件以捆绑 webpack
【发布时间】:2017-08-29 09:37:53
【问题描述】:

我需要将我的前端 javascript 文件捆绑到 bundle.js。 这是我的 webpack.config 文件,

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/]
    }
};

如何将我的前端 javascript 文件包含到包中?

【问题讨论】:

  • Webpack 配置不是您指定完整文件列表的地方。在您的入口脚本./bin/run.js 中,您将需要requireimport 其他文件(并让这些文件对更多文件执行类似操作,等等以形成依赖关系树)。 Webpack 在“概念”下记录了此选项 - ModulesModule Resolution
  • 知道了.. @JonathanLonowski 谢谢
  • 现在我在 jquery 中有错误,` F:\master QMS - Copy\QMS\node_modules\jquery\dist\jquery.js:31 throw new Error("jQuery 需要一个带有文档的窗口"); ^ 错误:jQuery 需要一个带有文档的窗口`我试过`new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery' }), ` this block, no使用@JonathanLonowski

标签: javascript node.js express webpack webpack-2


【解决方案1】:

如果你使用webpack2,那么你应该知道这个变化:

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

【讨论】:

    猜你喜欢
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 2019-11-15
    • 2020-04-03
    • 2016-01-26
    • 1970-01-01
    相关资源
    最近更新 更多