Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Make Webpack rebuilds fast

Patryk Zawadzkidcd9fc9cebc0
diff --git a/saleor/static/dashboard-next/storybook/webpack.config.js b/saleor/static/dashboard-next/storybook/webpack.config.js
index a0fd134a4b..e1b3b9957d 100644
--- a/saleor/static/dashboard-next/storybook/webpack.config.js
+++ b/saleor/static/dashboard-next/storybook/webpack.config.js
@@ -1,10 +1,19 @@
/* eslint-disable */
+const { CheckerPlugin } = require("awesome-typescript-loader")
+
module.exports = (baseConfig, env, config) => {
config.module.rules.push({
test: /\.tsx?$/,
exclude: /node_modules/,
- loader: require.resolve("awesome-typescript-loader")
+ loader: "awesome-typescript-loader",
+ options: {
+ reportFiles: [
+ "saleor/**/*.{ts,tsx}"
+ ],
+ useCache: true
+ }
});
config.resolve.extensions.push(".ts", ".tsx");
+ config.plugins.push(new CheckerPlugin());
return config;
};
diff --git a/webpack.config.js b/webpack.config.js
index d0be51befe..5772212193 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,55 +1,18 @@
-var BundleTracker = require('webpack-bundle-tracker');
-var MiniCssExtractPlugin = require('mini-css-extract-plugin');
-var path = require('path');
-var url = require('url');
-var webpack = require('webpack');
-var autoprefixer = require('autoprefixer');
+const autoprefixer = require('autoprefixer');
+const { CheckerPlugin } = require('awesome-typescript-loader');
+const MiniCssExtractPlugin = require('mini-css-extract-plugin');
+const path = require('path');
+const url = require('url');
+const webpack = require('webpack');
+const BundleTracker = require('webpack-bundle-tracker');
-var resolve = path.resolve.bind(path, __dirname);
+const resolve = path.resolve.bind(path, __dirname);
-var extractCssPlugin;
-var fileLoaderPath;
-var output;
-var reactPath;
-var reactDomPath;
-
-if (process.env.NODE_ENV === 'production') {
- const baseStaticPath = process.env.STATIC_URL || '/static/';
- const publicPath = url.resolve(baseStaticPath, 'assets/');
- reactPath = 'node_modules/react/cjs/react.production.min.js';
- reactDomPath = 'node_modules/react-dom/cjs/react-dom.production.min.js';
- output = {
- path: resolve('saleor/static/assets/'),
- filename: '[name].[chunkhash].js',
- chunkFilename: '[name].[chunkhash].js',
- publicPath: publicPath
- };
- fileLoaderPath = 'file-loader?name=[name].[hash].[ext]';
- extractCssPlugin = new MiniCssExtractPlugin({
- filename: '[name].[chunkhash].css',
- chunkFilename: '[id].[chunkhash].css'
- });
-} else {
- reactPath = 'node_modules/react/cjs/react.development.js';
- reactDomPath = 'node_modules/react-dom/cjs/react-dom.development.js';
- output = {
- path: resolve('saleor/static/assets/'),
- filename: '[name].js',
- chunkFilename: '[name].js',
- publicPath: '/static/assets/'
- };
- fileLoaderPath = 'file-loader?name=[name].[ext]';
- extractCssPlugin = new MiniCssExtractPlugin({
- filename: '[name].css',
- chunkFilename: '[name].css'
- });
-}
-
-var bundleTrackerPlugin = new BundleTracker({
+const bundleTrackerPlugin = new BundleTracker({
filename: 'webpack-bundle.json'
});
-var providePlugin = new webpack.ProvidePlugin({
+const providePlugin = new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
@@ -57,79 +20,128 @@ var providePlugin = new webpack.ProvidePlugin({
'query-string': 'query-string'
});
-var config = {
- entry: {
- dashboard: './saleor/static/dashboard/js/dashboard.js',
- 'dashboard-next': './saleor/static/dashboard-next/index.tsx',
- document: './saleor/static/dashboard/js/document.js',
- storefront: './saleor/static/js/storefront.js'
- },
- output: output,
- module: {
- rules: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loader: 'babel-loader'
- },
- {
- test: /\.scss$/,
- use: [
- MiniCssExtractPlugin.loader,
- {
- loader: 'css-loader',
- options: {
- 'sourceMap': true
- }
- },
- {
- loader: 'postcss-loader',
- options: {
- 'sourceMap': true,
- 'plugins': function () {
- return [autoprefixer];
+const checkerPlugin = new CheckerPlugin();
+
+module.exports = (env, argv) => {
+ const devMode = argv.mode !== 'production';
+
+ let extractCssPlugin;
+ let fileLoaderPath;
+ let output;
+ let reactPath;
+ let reactDomPath;
+
+ if (!devMode) {
+ const baseStaticPath = process.env.STATIC_URL || '/static/';
+ const publicPath = url.resolve(baseStaticPath, 'assets/');
+ reactPath = 'node_modules/react/cjs/react.production.min.js';
+ reactDomPath = 'node_modules/react-dom/cjs/react-dom.production.min.js';
+ output = {
+ path: resolve('saleor/static/assets/'),
+ filename: '[name].[chunkhash].js',
+ chunkFilename: '[name].[chunkhash].js',
+ publicPath: publicPath
+ };
+ fileLoaderPath = 'file-loader?name=[name].[hash].[ext]';
+ extractCssPlugin = new MiniCssExtractPlugin({
+ filename: '[name].[chunkhash].css',
+ chunkFilename: '[id].[chunkhash].css'
+ });
+ } else {
+ reactPath = 'node_modules/react/cjs/react.development.js';
+ reactDomPath = 'node_modules/react-dom/cjs/react-dom.development.js';
+ output = {
+ path: resolve('saleor/static/assets/'),
+ filename: '[name].js',
+ chunkFilename: '[name].js',
+ publicPath: '/static/assets/'
+ };
+ fileLoaderPath = 'file-loader?name=[name].[ext]';
+ extractCssPlugin = new MiniCssExtractPlugin({
+ filename: '[name].css',
+ chunkFilename: '[name].css'
+ });
+ }
+
+ return {
+ entry: {
+ dashboard: './saleor/static/dashboard/js/dashboard.js',
+ 'dashboard-next': './saleor/static/dashboard-next/index.tsx',
+ document: './saleor/static/dashboard/js/document.js',
+ storefront: './saleor/static/js/storefront.js'
+ },
+ output: output,
+ module: {
+ rules: [
+ {
+ test: /\.js$/,
+ exclude: /node_modules/,
+ loader: 'babel-loader'
+ },
+ {
+ test: /\.scss$/,
+ use: [
+ MiniCssExtractPlugin.loader,
+ {
+ loader: 'css-loader',
+ options: {
+ 'sourceMap': true
+ }
+ },
+ {
+ loader: 'postcss-loader',
+ options: {
+ 'sourceMap': true,
+ 'plugins': function () {
+ return [autoprefixer];
+ }
+ }
+ },
+ {
+ loader: 'sass-loader',
+ options: {
+ 'sourceMap': true
}
}
- },
- {
- loader: 'sass-loader',
- options: {
- 'sourceMap': true
- }
+ ]
+ },
+ {
+ test: /\.tsx?$/,
+ exclude: /node_modules/,
+ loader: 'awesome-typescript-loader',
+ options: {
+ reportFiles: [
+ 'saleor/**/*.{ts,tsx}'
+ ],
+ useCache: true
}
- ]
- },
- {
- test: /\.tsx?$/,
- exclude: /node_modules/,
- loader: 'awesome-typescript-loader'
+ },
+ {
+ test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/,
+ loader: fileLoaderPath,
+ include: [
+ resolve('node_modules'),
+ resolve('saleor/static/fonts'),
+ resolve('saleor/static/images'),
+ resolve('saleor/static/dashboard/images')
+ ]
+ }
+ ]
+ },
+ plugins: [
+ bundleTrackerPlugin,
+ extractCssPlugin,
+ providePlugin,
+ checkerPlugin
+ ],
+ resolve: {
+ alias: {
+ jquery: resolve('node_modules/jquery/dist/jquery.js'),
+ react: resolve(reactPath),
+ 'react-dom': resolve(reactDomPath)
},
- {
- test: /\.(eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/,
- loader: fileLoaderPath,
- include: [
- resolve('node_modules'),
- resolve('saleor/static/fonts'),
- resolve('saleor/static/images'),
- resolve('saleor/static/dashboard/images')
- ]
- }
- ]
- },
- plugins: [
- bundleTrackerPlugin,
- extractCssPlugin,
- providePlugin
- ],
- resolve: {
- alias: {
- jquery: resolve('node_modules/jquery/dist/jquery.js'),
- react: resolve(reactPath),
- 'react-dom': resolve(reactDomPath)
+ extensions: ['.ts', '.tsx', '.js', '.jsx']
},
- extensions: ['.ts', '.tsx', '.js', '.jsx']
- },
- devtool: 'sourceMap'
+ devtool: 'sourceMap'
+ };
};
-
-module.exports = config;