Webpack Example
See original GitHub issueI know that this is not the ideal place for this… I’m having trouble running a webpack with babel-loader. Would you have a more complete example of a configured webpack? I was not successful, following the documentation.
My webpack:
module.exports = (env = { NODE_ENV: 'development' }) => {
const prod = env.NODE_ENV === 'production';
// eslint-disable-next-line no-console
console.log(`MODE: ${prod ? 'PRODUCTION' : 'DEVELOPMENT'}`);
return {
entry: './src/index.tsx',
output: {
filename: '[name].[chunkhash].js',
path: path.resolve(__dirname, 'dist'),
},
mode: prod ? 'production' : 'development',
devtool: 'source-map',
...(prod
? {}
: { devServer: { historyApiFallback: true, hot: true, hotOnly: true } }),
plugins: [
// HTML Template
new HtmlWebpackPlugin({ template: './index.html' }),
new Style9Plugin(),
new MiniCssExtractPlugin(),
].filter(Boolean),
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.([tj])sx?$/,
use: [
Style9Plugin.loader,
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: 'last 1 chrome version' }],
[
'@babel/preset-react',
{
// Removes the need to import React into JSX files
runtime: 'automatic',
},
],
'@babel/preset-typescript',
],
plugins: [
// Fast Refresh
!prod && require.resolve('react-refresh/babel'),
].filter(Boolean),
cacheDirectory: true,
},
},
],
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(png|jpe?g|gif|woff2?|eot|otf|webp)$/i,
use: 'file-loader',
},
],
},
};
};
Error:
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Getting Started - webpack
Webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API.
Read more >Getting Started With Webpack - Smashing Magazine
An example is the sample package.json file below. Here, we use webpack to bundle the application without a configuration file:.
Read more >All You Need to Know about Webpack in Examples - Medium
1. Simplest project and Webpack installation;; 2. Configuration file;; 3. Regenerate bundle on file save;; 4. Using webpack-dev-server ...
Read more >A Beginner's Guide to Webpack - SitePoint
Learn the core concepts to help you get started with webpack, the popular static module bundler. We'll help you understand how webpack works ......
Read more >Webpack Tutorial for Beginners: A Complete Step ... - CodeinWP
Read this webpack tutorial for beginners to learn your first steps in bundling and serving HTML/JavaScript in an optimal fashion.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Was caused by incompatibility with Webpack 5. It should be fixed in 0.5.9.
repo: https://github.com/rodrigojcmello/style9-webpack
I disabled the style9 settings in the webpack just to make the application run. I also commented on the use in “src / components / Button / index.tsx”