Elv*_*ra 6 javascript css module webpack mini-css-extract-plugin
我正在使用 Webpack ^4.26.0。在用于 CSS 之前,我已经在 Webpack 3 中使用了“extract-text-webpack-plugin”。但是我已经读到该插件在 Webpack 4 上不再工作了。“extract-text-webpack-plugin”建议使用“mini-css-extract-plugin”插件。
我已经通过以下命令安装了插件:
npm install --save-dev mini-css-extract-plugin
并需要 webpackconfig 中的插件,还将其添加到我的规则和插件中:
// webpack.config.js
const webpack = require("webpack");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const config = {
context: path.resolve(__dirname),
entry: "./index.js",
devServer: {
contentBase: "./dist"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js"
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname),
use: [
{
loader: "babel-loader",
options: {
presets: [["@babel/env", { modules: false }], "@babel/react"]
}
}
]
},
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
}
],
noParse: [/aws-sdk/]
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.STATIC_PORT": JSON.stringify(process.env.STATIC_PORT),
VERSION: JSON.stringify(require("./package.json").version)
}),
new MiniCssExtractPlugin({
filename: 'bundle.css'
}),
new CopyWebpackPlugin([{ from: "./cb_icons", to: "cb_icons" }])
],
node: { fs: "empty" },
externals: [{ "./cptable": "var cptable" }, { "./jszip": "jszip" }]
};
module.exports = config;
Run Code Online (Sandbox Code Playgroud)
它安装在我的 node_modules 中:
组件/searchkit/node_modules/mini-css-extract-plugin
小智 0
默认情况下,Heroku 将安装 package.json 中的 dependency 和 devDependencies 下列出的所有依赖项。运行安装和构建步骤后,Heroku 将在部署应用程序之前删除 devDependencies 下声明的包。
来源: https: //devcenter.heroku.com/articles/nodejs-support
如果您在运行时需要 devDependency,您可以将其卸载并安装为运行时依赖项,或者将 heroku 环境变量设置为阻止修剪您的 devDependency。
在命令行中,它看起来像这样:
heroku config:set NPM_CONFIG_PRODUCTION=false
Run Code Online (Sandbox Code Playgroud)