我正在使用ASP.NET Core Angular 2模板:https://github.com/aspnet/JavaScriptServices#readme
我需要创建configuration.json文件,我有问题,因为我想将该文件复制到输出目录,如在wwwroot中。但这不是我想要的全部。我还需要应用程序查看该文件中的更改。因此,如果我在wwwroot / configuration.json中更改某些内容并重新启动应用程序,我应该会在应用程序中看到更改的数据。
当然,我需要这种行为而不需要任何重建应用程序。我想拥有已编译的应用程序,并能够将其复制到我需要的任意数量的实例,然后更改我的configuration.json文件。
我做了什么我进入project.json文件,然后将我的configuration.json复制到输出目录。文件正在复制,但在应用程序编译后我在该文件中更改了某些内容后,我看不到应用程序中的任何更改。
我希望webpack可以解决这个问题。不幸的是,我无法弄明白。
这是来自生成器的webpack.config文件。
var isDevBuild = process.argv.indexOf('--env.prod') < 0;
var path = require('path');
var webpack = require('webpack');
var merge = require('webpack-merge');
// Configuration in common to both client-side and server-side bundles
var sharedConfig = {
context: __dirname,
resolve: { extensions: [ '', '.js', '.ts' ] },
output: {
filename: '[name].js',
publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
loaders: [
{ test: /\.ts$/, include: /ClientApp/, loaders: ['ts-loader?silent=true', 'angular2-template-loader'] },
{ test: /vendor\/.+\.(jsx|js)$/,
loader: 'imports?jQuery=jquery,$=jquery,this=>window'
},
{
test: /[\/\\]node_modules[\/\\]some-module[\/\\]index\.js$/,
loader: "imports?this=>window"
},
{
test: /[\/\\]node_modules[\/\\]some-module[\/\\]index\.js$/,
loader: "imports?define=>false"
},
{ test: /\.html$/, loader: 'html-loader?minimize=false' },
{ test: /\.css$/, loader: 'to-string-loader!css-loader' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } },
{ test: /\.json$/, loader: 'json-loader' }
]
}
};
// Configuration for client-side bundle suitable for running in browsers
var clientBundleOutputDir = './wwwroot/dist';
var clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot-client.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
])
});
// Configuration for server-side (prerendering) bundle suitable for running in Node
var serverBundleConfig = merge(sharedConfig, {
resolve: { packageMains: ['main'] },
entry: { 'main-server': './ClientApp/boot-server.ts' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
})
],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map'
});
module.exports = [clientBundleConfig, serverBundleConfig];
我正在使用我的configuration.json文件,如:
let file = require('../configuration.json');