Comments (10)
This is the config file I got it to work with
// @flow
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const preCSS = require('precss');
const autoPrefixer = require('autoprefixer');
const extractCSS = new ExtractTextPlugin({
filename: '[name].fonts.css',
allChunks: true,
});
const extractSCSS = new ExtractTextPlugin({
filename: '[name].styles.css',
allChunks: true,
});
const BUILD_DIR = path.resolve(__dirname, 'build');
const SRC_DIR = path.resolve(__dirname, 'src');
const prodPlugins = [
new webpack.DefinePlugin({ // <-- key to reducing React's size
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
new webpack.optimize.AggressiveMergingPlugin(), // Merge chunks
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HardSourceWebpackPlugin(),
extractCSS,
extractSCSS,
new HtmlWebpackPlugin({
inject: true,
template: './public/index.html',
}),
new CopyWebpackPlugin(
[
{ from: './public/img', to: 'img' },
],
{ copyUnmodified: false },
),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
];
const devPlugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HardSourceWebpackPlugin(),
extractCSS,
extractSCSS,
new HtmlWebpackPlugin({
inject: true,
template: './public/index.html',
}),
new CopyWebpackPlugin(
[
{ from: './public/img', to: 'img' },
],
{ copyUnmodified: false },
),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
];
module.exports = (env = {}) => ({
mode: env.prod ? 'production' : 'development',
entry: {
index: ['babel-polyfill', `${SRC_DIR}/index.js`],
},
output: {
path: BUILD_DIR,
filename: '[name].bundle.js',
},
// watch: true,
devtool: env.prod ? 'source-map' : 'cheap-module-eval-source-map',
devServer: {
contentBase: BUILD_DIR,
// port: 9001,
compress: true,
hot: true,
open: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['es2015', 'react', 'env'],
plugins: ['transform-es2015-destructuring', 'transform-object-rest-spread', 'transform-class-properties'],
},
},
},
{
test: /\.html$/,
loader: 'html-loader',
},
{
test: /\.(scss)$/,
use: [{
loader: 'style-loader', // inject CSS to page
}, {
loader: 'css-loader',
options: { alias: { '../img': '../public/img' } },
}, {
loader: 'postcss-loader', // Run post css actions
options: {
plugins() { // post css plugins, can be exported to postcss.config.js
return [
preCSS,
autoPrefixer,
];
},
},
}, {
loader: 'sass-loader', // compiles Sass to CSS
}],
},
{
test: /\.css$/,
use: extractCSS.extract({
fallback: 'style-loader',
use: 'css-loader',
}),
},
{
test: /\.(png|jpg|jpeg|gif|ico)$/,
use: [
{
// loader: 'url-loader'
loader: 'file-loader',
options: {
name: './img/[name].[hash].[ext]',
},
},
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: './fonts/[name].[hash].[ext]',
},
}],
},
plugins: env.prod ? prodPlugins : devPlugins,
});
from coreui-free-react-admin-template.
@cvhong i recently ported a webpack 3 app to webpack 4. i'll push the config to github and post the link here. it's got similar things so should be a good basis to work from.
UPDATE
Here's the setup:
https://github.com/johnantoni/webpack4
from coreui-free-react-admin-template.
@ekeuus Can u share your package.json for coreui-free-react-admin-template ?
from coreui-free-react-admin-template.
awesome! thanks @ekeuus
from coreui-free-react-admin-template.
Hi, @johnantoni how to setup the command in script ? in package.json. I try many way but still got freeze at build.
from coreui-free-react-admin-template.
haven't tried the webpack 4 config @ekeuus posted should work by saving his config to webpack.config.js
then adding this start section to your package.json
"scripts": {
"start": "webpack-dev-server --open --config webpack.config.js",
"build": "NODE_ENV=production && webpack --config webpack.config.js"
},
and adding any missing packages to it via...
yarn add [missing package name] --dev
from coreui-free-react-admin-template.
Thank you for ur response @johnantoni I follow ur instruction but I use npm to install missing packages, but it return this error:
[Error] Error: Cannot find module 'react'
webpackMissingModule (bootstrap-table.js:9:88)
Eval Code (bootstrap-table.js:9:159)
eval
../../node_modules/react-bootstrap-table-next/lib/src/bootstrap-table.js (index.bundle.js:848)
[Error] Error: only one instance of babel-polyfill is allowed
(anonymous function) (index.js:10)
Eval Code (index.js:29)
eval
./node_modules/babel-polyfill/lib/index.js (index.bundle.js:1422)
__webpack_require__ (index.bundle.js:722)
fn (index.bundle.js:99)
(anonymous function) (index.bundle.js:11429)
__webpack_require__ (index.bundle.js:722)
(anonymous function) (index.bundle.js:789)
Global Code (index.bundle.js:790)
from coreui-free-react-admin-template.
Hi @johnantoni , I got problems solved, it was caused by I reinstall some of babel-... package.
from coreui-free-react-admin-template.
You can also use Webpack 4 without ejecting by upgrading to react-scripts@next, which uses webpack 4.8.3 and babel7.
And if you're ejecting just for HMR, use react-app-rewired instead.
from coreui-free-react-admin-template.
Hey @johnantoni , It seems there is another issue with this config, when I modify ./src/scss/_custom.scss , it is not regenerate new style.css again using this webpack config, any solution ?
from coreui-free-react-admin-template.
Related Issues (20)
- Tooltip position issue HOT 1
- Animation CCollapse at CSmartTable Doesn`t Work HOT 1
- npm run build failed HOT 4
- How can I put the itemsPerPageSelect to bottom of CDataTable? HOT 1
- Failed to compile on npm build HOT 2
- How to enable sidebar open by default on mobile devices? HOT 1
- React router dom v6 BrowserRouter not working on build version HOT 1
- `CNavGroup` icons not working on Coreui Free Admin Template ReactJS 4.3.0 HOT 1
- Dependency issue with "react-scripts" package HOT 1
- Modal (CModal) Closing Unexpectedly HOT 4
- Hash route not working in production mode HOT 1
- Template stops responding after a while on iPhone 12 HOT 2
- Config url # HOT 3
- Sidebar Opening and Closing Infinitely on Resizing
- Clean install. Navigation (buttons do not work). HOT 2
- can't run this dashboard
- How do I create a Logout link (with icon) at the footer of the sidebar ? (in React) HOT 3
- Charts tooltip doesn't have any style HOT 1
- Tailwind support HOT 1
- Tooltip not hiding
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coreui-free-react-admin-template.