2016-11-29 2 views
0

번역이 저장되는 다른 json 파일을 포함하는 Angular2/ASP.NET Core App에 폴더 (ClientApp/static/assets/i18n)가 있습니다. 예를 들어 http://localhost:54135/assets/i18n/en.json 아래의 브라우저에서 해당 파일을 사용할 수 있도록 공개 dist 폴더에 복사하고 싶습니다.webpack을 사용하여 공용 경로로 폴더를 복사하려면 어떻게해야합니까?

staticBundleConfig에서 webpack을 사용하여 어떻게 달성 할 수 있습니까? 시도했지만,이 경우 엔트리 포인트의 의미를 알 수 없습니다. 그것도 작동하지 않습니다. 그 달성에 도움이 되셨습니까? 그

var CopyWebpackPlugin = require('copy-webpack-plugin'); 
    plugins: [ 
      new CopyWebpackPlugin([    

       // Copy directory contents to {output}/to/directory/ 
       { from: 'from/directory', to: 'to/directory' } 
       ])    

      ], 

에 대한

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

http://stackoverflow.com/questions/27639005/how-to-copy- 대한 추가 정보를 원하시면이 링크를 따라 static-files-to-build-directory-with-webpack 시도해보기 –

+0

나는 그것을 시험해 보았고, 전달 된 js 파일에 하나의 파일을 묶어두기를 원한다. 내가하고 싶은 것은 폴더 안에 모든 json 파일들이있는 폴더를 전달하는 것입니다. – Stefan

+0

node_modules에서 타사 라이브러리를로드 할 수있는 방법이 있습니까? – Karthick

답변

1

를 사용하여 복사 웹팩 - 플러그인 click-here

+0

나는 이런 식으로 끝내지 못한다. 위 코드를 추가했습니다. 어쩌면 다시 확인해 주시겠습니까? – Stefan

+0

당신은 단지 모든 정적 자산을 루트 폴더에 복사하고 싶습니다. 그렇지 않으면 정적 또는 다른 이름의 폴더를 만들고 그 폴더에 정적 파일을 옮기고 싶습니까? – Sriram

+0

모든 정적 자산을 루트 폴더에 복사하기 만하면 브라우저가 다음과 같은 요청을 사용하여 찾을 수 있습니다. http : // localhost : 54135/assets/i18n/en.json – Stefan

관련 문제