我在应用程序中使用Webpack,在其中创建入口点为 index.ts,我试图使用sass css bootstrap typescript作为我的项目webpack中的资源运行它,但是我被这些错误所困扰,(bootstrap-loader):
./ node_modules / bootstrap-loader / no-op.js中的错误 (./node_modules/bootstrap-loader/lib/bootstrap.scripts.loader.js?{"bootstrapVersion":3,"useCustomIconFontPath":false,"extractStyles":false,"styleLoaders":["style-loader“,” css-loader“,” sass-loader“],” styles“:[” mixins“,” normalize“,” print“,” glyphicons“,” s 脚手架”,“类型”,“代码”,“网格”,“表”,“表单”,“按钮”,“组件动画”,“下拉列表”,“按钮组”,“输入组”,”导航”,“导航栏”,“面包屑”,“分页”,“传呼机”,“标签”,“徽章”,“巨型”,“缩略图”,“警报”,“进度条”,“媒体”,“列表组”,“面板”,“井”,“响应嵌入”,“关闭”,“模式”,“工具提示”,“弹出窗口”,“轮播”,“实用程序”,“响应实用程序”]] “脚本”:[“过渡”,“警报”,“按钮”,“轮播”,“折叠”,“下拉”,“模态”,“工具提示”,“弹出”,“滚动”,“标签”,“词缀”],“ configFilePath”:“ / projects / bootstrapwebpack / node_modules / bootstrap-loader / .bootstraprc-3-default”,“ bootstrapPath”:“ / projects / bootstrapwebpack / node_modules / bootstrap-sass”,“ bootstrapRelPath”:“ ../bootstrap-sass"}!../node_modules/bootstrap-loader/no-op.js) ...
在我的config.js中,我有:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: [ 'bootstrap-loader', './src/index.ts',],
module: {
rules:[
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
],
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
},
},
],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
exclude: /node_modules/
},
// Boooootstrap
{
test: /bootstrap-sass\/assets\/javascripts\//,
loader: 'imports-loader?jQuery=jquery'
},
{
test: /\.(woff2?|svg)$/, loader: 'url-loader?limit=10000'
},
{
test: /\.(ttf|eot)$/, loader: 'file-loader'
},
],
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
目前,我正在尝试在package.json中使用以下几行:
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "webpack --mode development --watch ",
"build": "webpack --progress -p --watch "
},
"dependencies": {
"autoprefixer": "^9.0.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"bootstrap": "^4.1.2",
"bootstrap-loader": "^3.0.0",
"bootstrap-sass": "^3.3.7",
"css-loader": "^1.0.0",
"exports-loader": "^0.7.0",
"file-loader": "^1.1.11",
"image-webpack-loader": "^4.3.1",
"jquery": "^3.3.1",
"mini-css-extract-plugin": "^0.4.1",
"node-sass": "^4.9.2",
"popper.js": "^1.14.3",
"postcss-loader": "^2.1.6",
"resolve-url-loader": "^2.3.0",
"sass-loader": "^7.0.3",
"style-loader": "^0.21.0",
"ts-loader": "^4.4.2",
"typescript": "^2.9.2",
"url-loader": "^1.0.1",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8"
}
}
答案 0 :(得分:0)
昨天我遇到了同样的问题。
尝试添加./src/index.ts
require 'bootstrap/dist/css/bootstrap.min.css';
require 'bootstrap/dist/js/bootstrap.min.js';