【发布时间】: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中,您将需要require或import其他文件(并让这些文件对更多文件执行类似操作,等等以形成依赖关系树)。 Webpack 在“概念”下记录了此选项 - Modules 和 Module 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