gpt4 book ai didi

javascript - 忽略来自 webpack 配置的 css 文件中的特定 @import

转载 作者:行者123 更新时间:2023-11-28 04:53:38 24 4
gpt4 key购买 nike

我有这个 webpack 配置

var Webpack = require("webpack");
var Path = require("path");
var OutputPath = "build";

module.exports = {

entry: "./src/app.tsx",
output: {
path: Path.join(__dirname, OutputPath, "" + process.env.NODE_ENV),
publicPath: "",
filename: "bundle.js"
},

devtool: "source-map",

devServer: {
contentBase: OutputPath
},

resolve: {
extensions: ["", ".ts", ".tsx", ".webpack.js", ".web.js", ".js", ".html"],
alias: {
jquery: "jquery/src/jquery"
}
},

node: {
fs: "empty"
},

module: {
loaders: [
{ test: /\.tsx?$/, loader: "ts-loader" },
{ test: /\.html$/, loader: "html-loader!file-loader?name=[name].[ext]" },

{ test: /\.ejs$/, loader: "ejs-loader" },

{
test: /\.svg$/,
loaders: [
"url-loader?limit=100000&name=assets/[name].[hash].[ext]",
"image-webpack?bypassOnDebug=false&optimizationLevel=7&interlaced=false"
]
},
{
test: /\.(png|jpe?g|gif|woff|woff2|ttf|eot|ico)$/,
loader: "url-loader?limit=100000&name=assets/[name].[hash].[ext]"
},
,
{
test: /\.css$/,
exclude: /.*onsenui.*$/,
loader: "ignore-loader"
}
,
{
test: /\.(less|css)$/,
exclude: /.*(font_awesome|ionicons|iconic-font).*$/,
loader: "style-loader!css-loader?-import!less-loader!postcss-loader"
}
],
}
};

应用程序是建立在 onsenui 上的,我试图忽略来自 css 导入的特定文件名。

@import url("font_awesome/css/font-awesome.min.css");
@import url("ionicons/css/ionicons.min.css");
@import url("material-design-iconic-font/css/material-design-iconic-font.min.css");

...

我们可以注释掉特定的行,但我们不想在每次更新 npm 包时都这样做。

有谁知道,如何忽略 css 导入?

最佳答案

最后我只是安装了“string-replace-webpack-plugin”并以这种方式使用。

var StringReplacePlugin = require("string-replace-webpack-plugin");

然后将该插件添加到预加载器中即可完成工作

preLoaders: [
{
test: /onsenui\.css$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /.*(@import).*/ig,
replacement: function (match, p1, offset, string) {
return "/*/";
}
}
]}),
include: /node_modules\\onsenui.*/
}
]

关于javascript - 忽略来自 webpack 配置的 css 文件中的特定 @import,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40547471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com