Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue-next): minify webpack bundle size #3983

Merged
merged 6 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
library: 'hippyReactBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyReactDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
library: 'hippyReactBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyReactDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = {
globalObject: '(0, eval)("this")',
},
plugins: [
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
inject: true,
scriptLoading: 'blocking',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
path: path.resolve(`./dist/${platform}/`),
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {
path: path.resolve(`./dist/${platform}/`),
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
path: path.resolve(`./dist/${platform}/`),
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyVueDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyVueDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyVueNextDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
// publicPath: 'https://xxx/hippy/hippyVueNextDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ exports.getWebpackSsrBaseConfig = function (platform, env) {
// publicPath: 'https://xxx/hippy/hippyVueNextDemo/',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ module.exports = {
globalObject: '(0, eval)("this")',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
library: 'hippyVueBase',
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__PLATFORM__: JSON.stringify(platform),
Expand Down
8 changes: 4 additions & 4 deletions driver/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions driver/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"module-alias": "^2.2.2",
"nyc": "^15.1.0",
"path-to-regexp": "^1.7.0",
"postcss-class-prefix": "~0.3.0",
"react": "^17.0.2",
"rimraf": "^2.6.3",
"rollup": "^2.79.1",
Expand All @@ -73,12 +74,11 @@
"trim-newlines": "^3.0.1",
"ts-jest": "^27.1.2",
"tslib": "^2.3.1",
"ttypescript": "^1.5.13",
"ttypescript": "~1.5.15",
"typescript": "^4.8.3",
"typescript-transform-paths": "^3.3.1",
"vue": "^2.6.14",
"watch": "^0.13.0",
"postcss-class-prefix": "~0.3.0"
"watch": "^0.13.0"
},
"_moduleAliases": {
"vue": "node_modules/vue/src/core/index",
Expand Down
33 changes: 13 additions & 20 deletions driver/js/packages/hippy-vue-css-loader/src/css-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@
* Convert the CSS text to AST that able to parse by selector parser.
*/
function hippyVueCSSLoader(this: any, source: any) {
const options = getOptions(this);

Check failure on line 33 in driver/js/packages/hippy-vue-css-loader/src/css-loader.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (16.x)

'options' is assigned a value but never used. Allowed unused vars must match /^_.+/u

Check failure on line 33 in driver/js/packages/hippy-vue-css-loader/src/css-loader.ts

View workflow job for this annotation

GitHub Actions / frontend_build_tests (17.x)

'options' is assigned a value but never used. Allowed unused vars must match /^_.+/u
const parsed = parseCSS(source, { source: sourceId });

const majorNodeVersion = parseInt(process.versions.node.split('.')[0], 10);
const hashType = majorNodeVersion >= 17 ? 'md5' : 'md4';
const hash = crypto.createHash(hashType);
const hash = crypto.createHash('shake256', { outputLength: 3 });
const contentHash = hash.update(source).digest('hex');
sourceId += 1;
const rulesAst = parsed.stylesheet.rules.filter((n: any) => n.type === 'rule').map((n: any) => ({
hash: contentHash,
selectors: n.selectors,

declarations: n.declarations.map((dec: any) => {
const rulesAst = parsed.stylesheet.rules.filter((n: any) => n.type === 'rule').map((n: any) => ([
contentHash,
n.selectors,
// filter comment declaration and empty declaration
n.declarations.filter(dec => dec.type !== 'comment').map((dec: any) => {
let { value } = dec;
const isVariableColor = dec.property?.startsWith('-') && typeof value === 'string'
&& (
Expand All @@ -55,18 +52,14 @@
if (dec.property && (dec.property.toLowerCase().indexOf('color') > -1 || isVariableColor)) {
value = translateColor(value);
}
return {
type: dec.type,
property: dec.property,
value,
};
return [dec.property, value];
}),
}));
const code = `(function() {
if (!global['${GLOBAL_STYLE_NAME}']) {
global['${GLOBAL_STYLE_NAME}'] = [];
])).filter(rule => rule[2].length > 0);
const code = `(function(n) {
if (!global[n]) {
global[n] = [];
}
global['${GLOBAL_STYLE_NAME}'] = global['${GLOBAL_STYLE_NAME}'].concat(${JSON.stringify(rulesAst)});
global[n] = global[n].concat(${JSON.stringify(rulesAst)});

if(module.hot) {
module.hot.dispose(() => {
Expand All @@ -77,7 +70,7 @@
global['${GLOBAL_DISPOSE_STYLE_NAME}'] = global['${GLOBAL_DISPOSE_STYLE_NAME}'].concat('${contentHash}');
})
}
})()`;
})('${GLOBAL_STYLE_NAME}')`;
return `module.exports=${code}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('style-parser/color-parser.ts', () => {
expect(translateColor('transparent')).toEqual(0);
expect(translateColor('blueviolet')).toEqual(4287245282);
expect(translateColor(4287245282)).toEqual(3808397867);
// FIXME custom variable
expect(translateColor('var(-Bg)')).toEqual('var(-Bg)');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import { SelectorsMap } from './css-selectors-match';
import { parseSelector } from './parser';
import { HIPPY_GLOBAL_STYLE_NAME, HIPPY_GLOBAL_DISPOSE_STYLE_NAME } from './';

type Declaration = [property: string, value: string | number];
export type ASTRule = [hash: string, selectors: string[], declarations: Declaration[]];

// style load hook
const beforeLoadStyleHook: Function = (declaration: Function): Function => declaration;

Expand Down Expand Up @@ -70,7 +73,7 @@ function createSimpleSelectorFromAst(ast) {
? new AttributeSelector(ast.property, ast.test, ast.value)
: new AttributeSelector(ast.property);
default:
return null;
return new InvalidSelector(new Error('Unknown selector.'));;
}
}

Expand Down Expand Up @@ -125,10 +128,23 @@ function createSelector(sel) {
* @param beforeLoadStyle
*/
export function fromAstNodes(
astRules: CssAttribute[] = [],
astRules: Array<CssAttribute | ASTRule> = [],
beforeLoadStyle?: Function,
): RuleSet[] {
return astRules.map((rule) => {
const rules = astRules.map(rule => {
if (!Array.isArray(rule)) return rule;
const [hash, selectors, declarations] = rule as ASTRule;
return {
hash,
selectors,
declarations: declarations.map(([property, value]) => ({
type: 'declaration',
property,
value,
})),
};
});
return rules.map((rule) => {
const declarations = rule.declarations
.filter(isDeclaration)
// use default hook when there is no hook passed in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const LINEAR_GRADIENT_DIRECTION_MAP = {
};

// degree unit
const DEGREE_UNIT = {
export const DEGREE_UNIT = {
TURN: 'turn',
RAD: 'rad',
DEG: 'deg',
Expand Down
Loading
Loading