Skip to content

Commit

Permalink
feat: pracel css
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjinyang authored Feb 11, 2022
1 parent 1a948d1 commit 150cb89
Show file tree
Hide file tree
Showing 39 changed files with 2,826 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ export default function ensureExtractLoader(
ruleUses.get('sass-loader').tap(args => {
return {
...args,
sourceMap: true,
sassOptions: {
outputStyle: 'expanded'
}
sourceMap: true
};
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/service/src/bundler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ export function createWebpackConfig(
const dev = mode === 'development';
let chain: WebpackChain;

const parcelCss = !!config.experimental.parcelCss;

const srcDirs = [paths.appDir, paths.srcDir, ...(opts.srcDirs || [])];
if (opts.node) {
chain = createNodeWebpackChain({
buildManifestFilename: BUILD_MANIFEST_PATH,
dev,
parcelCss,
env: config.env,
mediaFilename: BUILD_MEDIA_PATH,
name: opts.name,
Expand All @@ -51,6 +54,7 @@ export function createWebpackConfig(
analyze: config.analyze,
buildManifestFilename: BUILD_MANIFEST_PATH,
dev,
parcelCss,
env: config.env,
mediaFilename: BUILD_MEDIA_PATH,
name: opts.name,
Expand Down
3 changes: 3 additions & 0 deletions packages/service/src/core/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export interface UserConfig {
presets?: IPresetConfig[];
analyze?: boolean;
asyncEntry?: boolean;
experimental?: {
parcelCss?: boolean;
};
}

export interface Config
Expand Down
3 changes: 3 additions & 0 deletions packages/service/src/core/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const createDefaultConfig: () => UserConfig = () => ({
apiConfig: {
prefix: '/api',
bodyParser: true
},
experimental: {
parcelCss: false
}
});

Expand Down
3 changes: 3 additions & 0 deletions packages/toolpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
"ignore-loader": "0.1.2",
"loader-utils": "2.0.0",
"mini-css-extract-plugin": "1.3.9",
"css-minimizer-webpack-plugin": "3.4.1",
"path-browserify": "1.0.1",
"@parcel/css": "1.2.0",
"browserslist": "4.19.1",
"postcss": "8.2.3",
"postcss-flexbugs-fixes": "5.0.2",
"postcss-loader": "4.1.0",
Expand Down
27 changes: 20 additions & 7 deletions packages/toolpack/src/webpack/config/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import WebpackChain from 'webpack-chain';
import TerserPlugin from 'terser-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import webpack from 'webpack';
import path from 'path';
import {
Expand All @@ -23,6 +24,7 @@ const resolveLocalLoader = (name: string) =>

export interface BaseOptions {
dev: boolean;
parcelCss: boolean;
name: string;
projectRoot: string;
srcDirs: string[];
Expand Down Expand Up @@ -59,6 +61,7 @@ export { WebpackChain };

export function baseWebpackChain({
dev,
parcelCss,
projectRoot,
srcDirs,
mediaFilename,
Expand All @@ -85,6 +88,7 @@ export function baseWebpackChain({
minimize: !dev,
realContentHash: false
});

if (!dev) {
// @ts-ignore
config.optimization.minimizer('terser').use(TerserPlugin, [
Expand All @@ -94,6 +98,14 @@ export function baseWebpackChain({
terserOptions
}
]);
config.optimization.minimizer('cssMinimizer').use(CssMinimizerPlugin, [
{
// @ts-ignore
minify: parcelCss
? CssMinimizerPlugin.parcelCssMinify
: CssMinimizerPlugin.cssnanoMinify
}
]);
}

config.output.merge({
Expand Down Expand Up @@ -123,13 +135,14 @@ export function baseWebpackChain({
});

config.resolveLoader.merge({
alias: ['shuvi-swc-loader', 'route-component-loader'].reduce(
(alias, loader) => {
alias[`@shuvi/${loader}`] = resolveLocalLoader(loader);
return alias;
},
{} as Record<string, string>
)
alias: [
'shuvi-swc-loader',
'route-component-loader',
'parcel-css-loader'
].reduce((alias, loader) => {
alias[`@shuvi/${loader}`] = resolveLocalLoader(loader);
return alias;
}, {} as Record<string, string>)
});

config.module.set('strictExportPresence', true);
Expand Down
6 changes: 5 additions & 1 deletion packages/toolpack/src/webpack/config/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,9 @@ export function createBrowserWebpackChain({
}
]);

return withStyle(chain, { extractCss: !dev, publicPath });
return withStyle(chain, {
extractCss: !dev,
publicPath,
parcelCss: baseOptions.parcelCss
});
}
2 changes: 1 addition & 1 deletion packages/toolpack/src/webpack/config/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ export function createNodeWebpackChain({
}
]);

return withStyle(chain, { ssr: true });
return withStyle(chain, { ssr: true, parcelCss: baseOptions.parcelCss });
}
Loading

0 comments on commit 150cb89

Please sign in to comment.