2016-03-31 13 views
2

私はwebpack-dev-serverでディレクトリを提供しています。ただし、サブディレクトリ内のすべてのファイルは、アプリケーションによって単純に検出されません(404エラー)。Webpackはサブディレクトリ内のファイルを提供していませんか?

ので

dist 
--assets 
----i18n 
------en.json 
------es.json 
--main.bundle.js 
--vendor.bundle.js 
--(map files) 

を提供されているディレクトリの構造、main.bundle.jsvendor.bundle.jsはうまく提供されているが、assets/i18nディレクトリ内のJSONファイルが発見されていません。 Webpackの設定ファイルに何かがないと思われます。

webpack.config.js

// @AngularClass 

/* 
* Helper: root(), and rootDir() are defined at the bottom 
*/ 
var path = require('path'); 
var webpack = require('webpack'); 
var CopyWebpackPlugin = require('copy-webpack-plugin'); 
var HtmlWebpackPlugin = require('html-webpack-plugin'); 
var ENV = process.env.ENV = process.env.NODE_ENV = 'development'; 

var metadata = { 
    version: '0.0.1-alpha', 
    versionName: 'Bulbasaur', 
    baseUrl: '/appurl', 
    host: 'localhost', 
    port: 3000, 
    ENV: ENV 
}; 
/* 
* Config 
*/ 
module.exports = { 
    // static data for index.html 
    metadata: metadata, 
    // for faster builds use 'eval' 
    devtool: 'source-map', 
    debug: true, 

    // our angular app 
    entry: { 'vendor': './src/main/webapp/vendor.ts', 'main': './src/main/webapp/main.ts' }, 

    // Config for our build files 
    output: { 
    path: root('src/main/webapp/dist'), 
    //publicPath: './src/main/webapp/dist', 
    filename: '[name].bundle.js', 
    sourceMapFilename: '[name].map', 
    chunkFilename: '[id].chunk.js' 
    }, 

    resolve: { 
    // ensure loader extensions match 
    extensions: ['','.ts','.js','.json','.css','.html'] 
    }, 

    module: { 
    preLoaders: [{ test: /\.ts$/, loader: 'tslint-loader', exclude: [/node_modules/] }], 
    loaders: [ 
     // Support for .ts files. 
     { 
     test: /\.ts$/, 
     loader: 'ts-loader', 
     query: { 
      'ignoreDiagnostics': [ 
      2403, // 2403 -> Subsequent variable declarations 
      2300, // 2300 -> Duplicate identifier 
      2374, // 2374 -> Duplicate number index signature 
      2375 // 2375 -> Duplicate string index signature 
      ] 
     }, 
     exclude: [ /\.(spec|e2e)\.ts$/, /node_modules\/(?!(ng2-.+))/ ] 
     }, 

     // Support for *.json files. 
     { test: /\.json$/, loader: 'json-loader' }, 

     // Support for CSS as raw text 
     { test: /\.css$/, loader: 'raw-loader' }, 

     // support for .html as raw text 
     { test: /\.html$/, loader: 'raw-loader' } 

     // if you add a loader include the resolve file extension above 
    ] 
    }, 

    plugins: [ 
    new webpack.optimize.OccurenceOrderPlugin(true), 
    new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js', minChunks: Infinity }), 
    // static assets 
    new CopyWebpackPlugin([ { from: 'src/main/webapp/assets', to: 'assets' } ]), 
    // generating html 
    new HtmlWebpackPlugin({ template: 'src/main/webapp/index.html', inject: false }), 
    // replace 
    new webpack.DefinePlugin({ 
     'process.env': { 
     'ENV': JSON.stringify(metadata.ENV), 
     'NODE_ENV': JSON.stringify(metadata.ENV) 
     } 
    }) 
    ], 

    // Other module loader config 
    tslint: { 
    emitErrors: false, 
    failOnHint: false 
    }, 
    // our Webpack Development Server config 
    devServer: { 
    port: metadata.port, 
    host: metadata.host, 
    historyApiFallback: true, 
    watchOptions: { aggregateTimeout: 300, poll: 1000 } 
    }, 
    // we need this due to problems with es6-shim 
    node: {global: 'window', progress: false, crypto: 'empty', module: false, clearImmediate: false, setImmediate: false} 
}; 

// Helper functions 

function root(args) { 
    args = Array.prototype.slice.call(arguments, 0); 
    return path.join.apply(path, [__dirname].concat(args)); 
} 

function rootNode(args) { 
    args = Array.prototype.slice.call(arguments, 0); 
    return root.apply(path, ['node_modules'].concat(args)); 
} 

私は取捨選択やドキュメントを理解しようとしている...のWebPACKに新たなんだけど、私はあまり進展していませんよ。私は何が欠けているかに関する任意のアイデア?

答えて

1

webpack-dev-serverコマンドに--content-base static/files/to/serve/と指定する必要がありました。

関連する問題