Reputation: 1266
My issue is that I have a webpack project where I include typescript classes / types / css files and resources outside the "src dir" of the project. So basically only files within the "src" folder should be included, no files outside that directory or even higher in file hierarchy.
These files outside the project dir should not be included in the built, since they are already existing on runtime. As far as I understood this can achieve by using the resolve function.
include: path.resolve(__dirname, 'src')
That only results in the error "ReferenceError: path is not defined". I don't know where I would define it actually.
I think this is a rather simple question, but I seem not to find the solution to it. I am using webpack 4.44.1 and webpack-cli 3.3.12 .
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const path = require("path")
module.exports = {
optimization: {
minimize: false
},
entry: {
'code': './src/code.ts'
},
plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['public/build']
}),
],
output: {
path: __dirname + '/public',
//filename: 'build/[name].[contenthash].js',
filename: 'build/[name].js',
},
module: {
rules: [
{
test: /\.ts?$/, use: 'ts-loader', exclude: /node_modules/
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2|json|xml|ico|cur|ani)$/,
use: ['file-loader?name=[path][name].[ext]']
},
]
},
resolve: {
extensions: [
'.ts',
'.js',
'.json',
],
},
};
Upvotes: 0
Views: 428
Reputation: 21
You need to import path library before you can use it. Please add this to top of webpack.config.js e.g const path = require("path")
or if you are using ES6 you can use import path from "path";
Upvotes: 2