當我運行webpack時,我的javascript資源沒有按照正確的順序編譯。 正確的順序應該是Webpack 2沒有以正確的順序編譯文件
- jQuery的
- 引導
然而,遵守包文件包含自舉第一則jQuery的。請參考下面
webpack.config
var path = require('path');
var webpack = require('webpack');
var extractTextPlugin = require('extract-text-webpack-plugin');
var cleanWebpackPlugin = require('clean-webpack-plugin');
var jsDestPath = './wwwroot/';
const config = {
entry: {
css: './Assets/scss/app.scss',
app: './Assets/js/app.js',
vendor: './Assets/js/vendor.js'
},
output: {
path: path.resolve(__dirname, 'wwwroot/js'),
filename: '[chunkhash].[name].js'
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader'
},
{
test: /\.scss$/,
loader: extractTextPlugin.extract({
loader: 'css-loader!sass-loader'
})
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'] //Specify the common bundle's name.
}),
new extractTextPlugin({ filename: 'bundle.css', disable: false, allChunks: true}),
new webpack.LoaderOptionsPlugin({
debug: true,
minimize: true,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: true,
}
}),
new cleanWebpackPlugin(['js'], {
root: jsDestPath,
verbose: true,
dry: false
})
],
}
module.exports = config;
vendor.js
import 'jquery/dist/jquery.js';
import 'bootstrap/dist/js/bootstrap.js';
感謝您的評論。但是,當頁面加載時,我得到的錯誤控制檯中沒有定義jQuery。 Bootstrap依賴於Jquery。 –
@ErkanDemir,你有沒有得到答案呢? – icfantv