Skip to content

Commit

Permalink
Merge pull request #29 from lbmaian/devmode
Browse files Browse the repository at this point in the history
Development mode build improvements
  • Loading branch information
KentoNishi authored Dec 3, 2021
2 parents 4980d47 + 1704fb2 commit 3472561
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
35 changes: 17 additions & 18 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const safelistPatterns = [
/^[mphw]\w?-\d\.5$/
];

module.exports = (purge = false) => {
module.exports = (minify = false) => {
const postcss = [];
return [
require('postcss-import')(),
Expand All @@ -29,23 +29,22 @@ module.exports = (purge = false) => {
require('autoprefixer')(),
require('tailwindcss')(tailwindConfig),
...postcss,
purge &&
require('cssnano')({
preset: 'default'
}),
purge &&
require('@fullhuman/postcss-purgecss')({
content: ['./**/*.svelte'],
extractors: [
{
extractor,
extensions: ['svelte']
}
],
safelist: {
standard: safelistSelectors,
deep: safelistPatterns
minify && require('cssnano')({
preset: 'default'
}),
// Always tree shake CSS even in development mode for ~99% size reduction
require('@fullhuman/postcss-purgecss')({
content: ['./**/*.svelte'],
extractors: [
{
extractor,
extensions: ['svelte']
}
})
],
safelist: {
standard: safelistSelectors,
deep: safelistPatterns
}
})
].filter(Boolean);
};
40 changes: 23 additions & 17 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const extReloader = new ExtReloader({
reloadPage: true
});

const transformManifest = (manifestString, version, isChrome = false) => {
const transformManifest = (manifestString, version, prod, isChrome = false) => {
const newManifest = {
...JSON.parse(manifestString),
version
};
if (isChrome) newManifest.incognito = 'split';
return JSON.stringify(newManifest);
return JSON.stringify(newManifest, null, prod ? 0 : 2);
};

module.exports = (env, options) => {
Expand All @@ -34,6 +34,7 @@ module.exports = (env, options) => {

const envVersion = env.version;
const hasEnvVersion = (envVersion != null && typeof envVersion === 'string');
const watch = env.WEBPACK_WATCH;

const cssConfig = {
test: /\.(sa|sc|c)ss$/,
Expand Down Expand Up @@ -87,7 +88,7 @@ module.exports = (env, options) => {
dev: !prod // Built-in HMR
},
emitCss: false,
hotReload: !prod,
hotReload: !prod && watch,
preprocess
}
}
Expand All @@ -102,6 +103,9 @@ module.exports = (env, options) => {
cssConfig
]
},
optimization: {
concatenateModules: true // concatenate modules even in development mode for cleaner output
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
Expand All @@ -112,15 +116,15 @@ module.exports = (env, options) => {
},
{
from: 'src/manifest.json',
transform: (content) => {
return transformManifest(content, hasEnvVersion ? envVersion : version);
transform(content) {
return transformManifest(content, hasEnvVersion ? envVersion : version, prod);
}
},
{
from: 'src/manifest.json',
to: 'manifest.chrome.json',
transform: (content) => {
return transformManifest(content, hasEnvVersion ? envVersion : version, true);
transform(content) {
return transformManifest(content, hasEnvVersion ? envVersion : version, prod, true);
}
}
]
Expand All @@ -139,16 +143,18 @@ module.exports = (env, options) => {
config.devtool = false;
} else {
config.devtool = 'eval-cheap-module-source-map';
config.plugins.push(new webpack.HotModuleReplacementPlugin(), extReloader);
// config.devServer = {
// host: 'localhost',
// port: 6000,
// hot: true,
// contentBase: path.join(__dirname, 'build'),
// headers: { 'Access-Control-Allow-Origin': '*' },
// writeToDisk: true,
// disableHostCheck: true
// };
if (watch) {
config.plugins.push(new webpack.HotModuleReplacementPlugin(), extReloader);
// config.devServer = {
// host: 'localhost',
// port: 6000,
// hot: true,
// contentBase: path.join(__dirname, 'build'),
// headers: { 'Access-Control-Allow-Origin': '*' },
// writeToDisk: true,
// disableHostCheck: true
// };
}
}

return config;
Expand Down

0 comments on commit 3472561

Please sign in to comment.