这些是webpack.config.js文件的内容
var webpack = require('webpack');
var path = require('path');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
module.exports = {
entry: [
'script!jquery/dist/jquery.min.js',
'script!foundation-sites/dist/foundation.min.js',
'./app/app.jsx'
],
externals:{
jquery: 'jQuery'
},
plugins:[
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
],
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve:{
root: __dirname,
modulesDirectories: [
'node_modules',
'./app/components',
'./app/api'
],
alias: {
app: 'app',
applicationStyles:'app/styles/app.scss',
actions:'app/actions/actions.jsx',
reducers:'app/reducers/reducers.jsx',
configureStore:'app/store/configureStore.jsx'
},
extensions: ['','.js',['.jsx']]
},
module:{
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['react','es2015','stage-0']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
},
sassLoader:{
includePaths:[
path.resolve(__dirname,'./node_modules/foundation-sites/scss')
]
},
devtool: process.env.NODE_ENV === 'production' ? undefined : 'inline-source-map'
};
,这些是package.json文件的内容
{
"name": "boilerplate",
"version": "1.0.0",
"description": "Simple react app",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test karma start",
"build":"webpack",
"start": "npm run build && node server.js"
},
"author": "varun",
"license": "MIT",
"dependencies": {
"axios": "^0.15.3",
"express": "^4.14.0",
"firebase": "^3.0.2",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-router": "^2.0.0",
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.16.0",
"css-loader": "^0.23.1",
"deep-freeze-strict": "^1.1.1",
"expect": "^1.14.0",
"foundation-sites": "^6.2.0",
"jquery": "^2.2.1",
"moment": "^2.12.0",
"node-sass": "^3.13.0",
"node-uuid": "^1.4.7",
"react-addons-test-utils": "^0.14.7",
"react-redux": "^4.4.1",
"redux": "^3.3.1",
"redux-mock-store": "^1.0.3",
"redux-thunk": "^2.1.0",
"sass-loader": "^4.0.2",
"script-loader": "^0.6.1",
"style-loader": "^0.13.0",
"webpack": "^1.12.13"
},
"devDependencies": {
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.2",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"mocha": "^2.4.5"
}
}
当我将此应用程序部署到heroku并使用命令'heroku open'打开应用程序时,我得到以下错误 r
错误:无法找到模块“script!foundation-sites / dist / foundation.min.js”
如果有人能指出这里有什么问题会很棒。似乎无法解决这个问题。 PS。当我在本地运行时,该应用程序运行良好
答案 0 :(得分:5)
我无论如何都不是Webpack专家,但是我在使用我设置的样板时遇到了同样的问题。经过一个小时的挫折,我意识到node_modules中的foundation-sites目录的结构已经改变,文件foundation_min.js
已被移动到dist内的js目录中。
长话短说,我用“script!foundation-sites/dist/foundation.min.js
”替换了“script!foundation-sites/dist/**js**/foundation.min.js
”,现在一切正常。我也使用版本6.2.0的基础网站,所以这可能是你的问题。
答案 1 :(得分:4)
在webpack.config.js文件中,您需要更改以下路径。
module.exports = {
entry: ['script!jquery/dist/jquery.min.js',
'script!foundation-sites/dist/js/foundation.min.js',
'./app/app.jsx'
]
}
您可以为CSS
分配 app.jsx 的路径require('style!css!foundation-sites/dist/css/foundation.min.css');