我的Angular2 / ASP.NET核心应用程序中有一个文件夹(ClientApp / static / assets / i18n),其中包含存储翻译的不同json文件。我想将它们复制到public dist文件夹,以便文件可用于Android Gradle Duplicate files copied in APK META-INF/license.txt下的浏览器。
如何使用带有staticBundleConfig的webpack实现这一点。我已经尝试过了,但在这种情况下,我并没有完全理解入口点的含义。它也不起作用。有没有帮助实现这一目标?
var isDevBuild = process.argv.indexOf('--env.prod') < 0;
var path = require('path');
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var nodeExternals = require('webpack-node-externals');
var merge = require('webpack-merge');
var allFilenamesExceptJavaScript = /\.(?!js(\?|$))([^.]+(\?|$))/;
// Configuration in common to both client-side and server-side bundles
var sharedConfig = {
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/, loader: 'ts', query: { silent: true } },
{ test: /\.html$/, loader: 'raw' },
{ test: /\.json$/, include: /ClientApp/, loader: 'json'},
{ test: /\.css$/, loader: 'to-string!css' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url', query: { limit: 25000 } }
]
}
};
// Configuration for client-side bundle suitable for running in browsers
var clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot-client.ts' },
output: { path: path.join(__dirname, './wwwroot/dist') },
devtool: isDevBuild ? 'inline-source-map' : null,
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [] : [
// Plugins that apply in production builds only
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
])
});
var staticBundleConfig = merge(sharedConfig, {
//entry: { 'static': './ClientApp/boot.ts' },
output: { path: path.join(__dirname, './wwwroot/dist') },
plugins: [
new CopyWebpackPlugin([
{ from: './ClientApp/static', to: path.join(__dirname, './wwwroot/dist') }
])
]
});
// Configuration for server-side (prerendering) bundle suitable for running in Node
var serverBundleConfig = merge(sharedConfig, {
entry: { 'main-server': './ClientApp/boot-server.ts' },
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map',
externals: [nodeExternals({ whitelist: [allFilenamesExceptJavaScript] })] // Don't bundle .js files from node_modules
});
module.exports = [clientBundleConfig, serverBundleConfig, staticBundleConfig];
答案 0 :(得分:1)
使用copy-webpack-plugin
var CopyWebpackPlugin = require('copy-webpack-plugin');
plugins: [
new CopyWebpackPlugin([
// Copy directory contents to {output}/to/directory/
{ from: 'from/directory', to: 'to/directory' }
])
],
点击此链接获取更多信息click-here