2016-09-01 245 views
5

一切運行良好,但無法找到我的dist文件夾在哪裏。我按照文檔使用了publicPath,dist文件夾似乎來自內存。未在項目文件夾中創建Webpack dist文件夾?

這可能是個小問題,我是webpack的新手。任何幫助將工作

下面是我webpack.config.js文件

var path = require('path') 
var webpack = require('webpack') 
var HtmlWebpackPlugin = require('html-webpack-plugin') 

module.exports = { 
    entry: "./src/index.js", 
    output: { 
     path: path.join(__dirname,'dist'), 
     filename: "[name].js", 
     publicPath:'/dist' 
    }, 
    plugins: [ 
     new HtmlWebpackPlugin({ 
      template: './src/index.html' 
     }) 
    ], 
    module: { 
     loaders: [ 
      { 
       test: /\.css$/, loader: "style-loader!css-loader" 
      }, 
      { 
       test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/, 
       loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]' 
      }, 
      { 
       test: /\.js$/, 
       exclude: /(node_modules|bower_components)/, 
       loader: 'babel', 
       query: { 
        presets: ['es2015', 'react', 'stage-2'] 
       } 
      } 
     ] 
    }, 
    devServer: { 
     historyApiFallback: true, 
     stats:'error-only' 
    } 
}; 

我的package.json文件

{ 
    "name": "tryout", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "test": "mocha './tests/**/*.test.js' --compilers js:babel-core/register --recursive", 
    "start-dev-server": "webpack-dev-server --content-base dist/ --port 6969", 
    "s": "npm run start-dev-server", 
    "test:watch": "npm test -- --watch" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "babel-core": "^6.13.2", 
    "babel-loader": "^6.2.4", 
    "babel-polyfill": "^6.13.0", 
    "babel-preset-es2015": "^6.13.2", 
    "babel-preset-react": "^6.11.1", 
    "babel-preset-stage-2": "^6.13.0", 
    "es6-promise": "^3.2.1", 
    "file-loader": "^0.9.0", 
    "html-webpack-plugin": "^2.22.0", 
    "isomorphic-fetch": "^2.2.1", 
    "lodash": "^4.15.0", 
    "react": "^15.3.0", 
    "react-dom": "^15.3.0", 
    "react-redux": "^4.4.5", 
    "react-router": "^2.6.1", 
    "react-router-redux": "^4.0.5", 
    "redux": "^3.5.2", 
    "redux-thunk": "^2.1.0", 
    "url-loader": "^0.5.7", 
    "webpack": "^1.13.1", 
    "webpack-dev-server": "^1.14.1" 
    }, 
    "devDependencies": { 
    "babel-register": "^6.11.6", 
    "css-loader": "^0.23.1", 
    "enzyme": "^2.4.1", 
    "expect": "^1.20.2", 
    "mocha": "^3.0.2", 
    "nock": "^8.0.0", 
    "react-addons-test-utils": "^15.3.1", 
    "redux-mock-store": "^1.1.4", 
    "style-loader": "^0.13.1" 
    } 
} 
+0

「publicPath」被幾個Webpack的插件用來在生成生產版本時更新CSS,HTML文件中的URL。因此它不會對你的開發環境有任何影響https://medium.com/@rajaraodv/webpack-the-confusing-parts-58712f8fcad9#.1j9bauc10 – erichardson30

+0

我可以通過webpack -p在本地創建dist文件夾。但是,這不會在本地工作,因爲它只創建分發代碼不會發生與服務器啓動和指向dist文件夾。這可以在本地機器上實現嗎? –

回答

13

仍然DIST文件夾似乎從內存來

很可能是因爲您正在使用webpack-dev-server(這就是它的作用)。

如果您希望將捆綁資產實際寫入磁盤,請運行webpack

+0

grt這項工作!解決了我的困惑。在disck上創建dist文件夾後,CLI會在localhost:port-number上獲取退出。有關如何從dist文件夾運行應用程序的任何參考資料,請參閱本地 –

+0

@PradeepJaiswar,它取決於您的應用程序,它可能與['http-server'](https://github.com/indexzero/http) -服務器)。 – robertklep

相關問題