我最近嘗試將我的應用程序從Webpack 1.x升級到2.x([email protected]),並且在從here和here ,我可以運行該應用程序,但bootstrap被徹底刪除。當我檢查元素時,css類不加載(不在開發人員工具中顯示)。裝載機是否存在問題?從Webpack 1.x遷移到Webpack 2.x的問題
webpack.common.js
const webpack = require('webpack');
const helpers = require('./helpers');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const METADATA = {
title: 'App',
baseUrl: '.'
};
var jQuery = require('jquery');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'main': './src/main.browser.ts'
},
externals: {
"jQuery": "jQuery"
},
resolve: {
alias: {
jquery: "jquery/dist/jquery.min"
},
extensions: ['.ts', '.js'],
modules: [
helpers.root('src'),
'node_modules'
]
},
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
loader: 'source-map-loader',
exclude: [
helpers.root('node_modules/rxjs'),
helpers.root('node_modules/primeng')
]
},
{
test: /\.js$/,
loader: 'babel-loader'
},
{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
},
{
test: /\.css$/,
loader: 'raw-loader'
},
{
test: /\.html$/,
loader: 'raw-loader'
// exclude: [helpers.root('src/index.html')]
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
"raw-loader",
"sass-loader"
]
},
{
test: /\.(woff|woff2|ttf|eot|svg)$/,
loader: "url-loader",
options: {
limit: 10000
}
}
]
},
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
metadata: METADATA,
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
}
}
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
helpers.root('src'),
{}
),
new webpack.ProvidePlugin({
"window.Tether": "tether",
_: 'lodash',
$: "jquery",
jQuery: "jquery"
}),
new webpack.optimize.CommonsChunkPlugin({
name: helpers.reverse(['polyfills', 'vendor'])
}),
new ExtractTextPlugin({
filename: "node_modules/fullcalendar/dist/fullcalendar.min.css",
allChunks: true
}),
new CopyWebpackPlugin(
[
{
from: 'src/server-components',
to: 'server-components'
},
{
from: 'src/assets',
to: 'assets'
},
{
from: 'src/shared-files',
to: 'shared-files'
}
]
),
new HtmlWebpackPlugin({
template: 'src/index.html',
chunksSortMode: helpers.packageSort(['polyfills', 'vendor', 'main'])
})
],
node: {
global: true,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
我在做這些webpack.common.js變化,但沒有改變。 Css或bootstrap仍然無法加載 – user3344978
您需要添加此https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/config/webpack.config.prod.js#L297- L299在你的插件部分,你做到了嗎? –
Angular應用程序也一樣嗎? – user3344978