我有一个外部JSON,通过导入" CustomerConfig"我可以在我的反应应用程序中访问它。文件。但我不希望它在缩小的捆绑文件中。如何排除customer-config.json
被捆绑?
这是我在webpack中的基本配置:
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const PATHS = {
app: path.join(__dirname, '..', 'app'),
dist: path.join(__dirname, '..', 'dist'),
};
export default {
entry: [PATHS.app],
output: {
path: PATHS.dist,
filename: 'bundle.js',
publicPath: '/',
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
externals: {
customerConfig: JSON.stringify(require('../app/customer-config.json')),
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel?cacheDirectory',
include: PATHS.app,
},
{
test: /\.((woff2?|svg)(\?v=[0-9]\.[0-9]\.[0-9]))|(woff2?|svg)$/,
loader: 'url?limit=10000',
},
{
test: /\.((ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9]))|(ttf|eot)$/,
loader: 'file',
},
{
test: /\.png$/,
loader: 'url-loader?limit=100000&mimetype=image/png&name=[path][name].[hash].[ext]',
},
{
test: /\.docx$/,
loader: 'file?name=[name].[ext]',
},
{
test: /\.pdf$/,
loader: 'file?name=[name].[ext]',
},
{
test: /\.ico$/,
loader: 'file?name=[name].[ext]',
},
{
test: /\.jpg$/,
loader: 'file-loader?name=[path][name].[hash].[ext]',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
inject: 'body',
title: 'React Redux Starter',
}),
],
};
答案 0 :(得分:0)
您可以尝试这样的事情:
exclude: {
exclude: [
'src/config/yourfile.json'
]
}