Reputation: 83
Here's my webpack.config.js code
module.exports = {
entry: "./app/assets/scripts/App.js",
output: {
path: "/C/Users/noob/Documents/jay/Sites/travel-site/app/temp/scripts",
filename: "App.js"
}
}
Here's the webpack output. Problem is it's not creating scripts folder and the App.js file under temp directory
Upon editing the path name to path.resolve here's the error
Upvotes: 0
Views: 3003
Reputation: 83
Solved with this line of codes
module.exports = {
entry: "./app/assets/scripts/App.js",
output: {
path: __dirname + "/app/temp/scripts",
filename: "App.js"
}
}
Upvotes: 0
Reputation: 32972
Using an absolute path written by hand is fragile because if you decide to move the directory of your project, you'll still output to the old location. Additionally, paths on Windows are a whole different story. You're better off using the Node.js built-in path
module, which creates the correct path for your operating system. To create an absolute path you can use path.resolve
.
const path = require('path');
module.exports = {
entry: "./app/assets/scripts/App.js",
output: {
path: path.resolve(__dirname, "app/temp/scripts"),
filename: "App.js"
}
}
__dirname
is the directory of the currently executed file (your webpack config).
With this configuration you will always output to the directory ./app/temp/scripts/
relative to your project, no matter where the project is located.
Upvotes: 1