javascript - 与 webpack 捆绑时排除文件
问题描述
我试图从捆绑文件中排除文件,通过使用 webpack 我有一个目录:
-- src
--assets
-- main.js
--config
-- config.js
在 main.js 中,我已经导入了 config.js
import * as envConfig from '../../config/config.js'
这是 webpack 配置:
var path = require('path');
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin')
var config = {
entry: {
main: './index.js'
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, "dist"),
},
plugins: [
new CopyWebpackPlugin([{
from: '*.html',
to: path.resolve(__dirname, "dist"),
},
{
from: './assets/images/*',
to: path.resolve(__dirname, "dist"),
}
])
],
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/, /config/],
use: 'babel-loader'
},
{
test: /\.(png|jp(e*)g|svg|woff(2)?|ttf|eot|json)$/,
use: 'url-loader'
},
{
test: /\.(sa|sc|c)ss$/,
use: ["style-loader", "css-loader?url=false"]
},
{
test: /\.html$/,
exclude: /node_modules/,
use: 'html-loader'
}
]
},
performance: { hints: false },
node: {
fs: "empty"
}
};
module.exports = config;
问题是我想将 config.js 从 main.js 中排除,我不希望捆绑文件(main.js)中包含 config.js 的内容,但是在构建之后我仍然可以看到它的内容。
解决方案
推荐阅读
- javascript - jQuery在页面上显示文本输入
- python - Python - 返回2个队列的组合
- tensorflow - 问一个机器学习再训练模型“这对你来说是什么样的?”
- reactjs - 反应路由器onEnter替换不起作用
- python - 在 Mac OS 上使用 anaconda 环境的 Swig 引发致命的 Python 错误:PyThreadState_Get: no current thread
- javascript - 带有确认消息脚本的谷歌浏览器中的问题
- mysql - 即使在连接参数中提供了远程服务器 IP,Sqoop 导入也总是尝试连接到本地 mysql
- java - 不使用 sun.security 或 bouncycastle 在 java 程序中生成 X.509 证书
- javascript - 如果有参数,函数不起作用
- android - 无法通过 whatsapp 分享图片链接