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

@wordpress/scripts deletes files #24111

Closed
Lewiscowles1986 opened this issue Jul 22, 2020 · 5 comments
Closed

@wordpress/scripts deletes files #24111

Lewiscowles1986 opened this issue Jul 22, 2020 · 5 comments
Labels
[Package] Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@Lewiscowles1986
Copy link
Contributor

Describe the bug

Following the instructions on @wordpress/scripts leads to files deleting themselves.

To reproduce
Steps to reproduce the behavior:

  1. add the import and splats from the @wordpress/scripts npm (trying to reduce package size)
  2. run npm run build
  3. observe many missing files (not sent to recycle bin or trash, but permanently deleted... WTAF)

Expected behavior

Not deleting, reverting or modifying files without a prompt to confirm (minimize any user surprise)

Additional context

This is when using the @wordpress/scripts package at version 12.1.1 windows 64-bit using vscode & git bash.

@Lewiscowles1986 Lewiscowles1986 changed the title @wordpress/scripts @wordpress/scripts deletes files Jul 22, 2020
@Soean Soean added the [Package] Scripts /packages/scripts label Jul 22, 2020
@Soean
Copy link
Member

Soean commented Jul 22, 2020

This feature was added in #23135 to clean up the build folder. If you have other build scripts maybe use a subfolder for the output of the wordpress scripts.

@ocean90

@Lewiscowles1986
Copy link
Contributor Author

Lewiscowles1986 commented Jul 22, 2020

What I've done instead (for now at least) is not used @wordpress/scripts, but rather @wordpress/dependency-extraction-webpack-plugin which was the part I wanted. (1.75MB when using Storybook as I had to use import instead of sneakily relying on globals). It's now down to < 10KB which is lower than the starting point of >10KB <20KB

The files going missing were in {repo}/src and included:

  • lib
  • media
  • node_modules
  • storybook
webpack.config.js
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );

var config = {
	entry: './index.js',
	output: {
		path: __dirname,
		filename: 'block.build.js',
	},
	module: {
		rules: [
			{
				test: /\/stories\/.+\.js$/,
				loaders: [ require.resolve( '@storybook/source-loader' ) ],
				enforce: 'pre',
			},
			{
				test: /.js$/,
				loader: 'babel-loader',
				exclude: /node_modules/,
			},
			{
				test: /.scss$/,
				loader: 'sass-loader',
			}
		],
	},
	plugins: [],
};

module.exports = (env, argv) => {
	if (argv.mode === 'development') {
		config.devtool = 'source-map';
	}

	if(process.env.WP_NO_EXTERNALS) {
		config.plugins.push(
			new DependencyExtractionWebpackPlugin( {
				injectPolyfill: true,
				outputFormat: 'json'
			})
		);
	}

	return config;
};

It seems to have fixed the issue for-now. I may have to spend a lot more time to bring the repo (2017 I think) in-line with 2020 😁

@Lewiscowles1986
Copy link
Contributor Author

I also can't think of why https://www.npmjs.com/package/clean-webpack-plugin would be the culprit. It's defaults and the usage seem to suggest this is something else.

@ocean90
Copy link
Member

ocean90 commented Jul 22, 2020

By default clean-webpack-plugin deletes everything defined in output.path. In your example it's __dirname so it deletes everything in the same directory as the config is. You should use a separate output directory. See the default config for an example.

@ocean90 ocean90 added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Jul 22, 2020
@gziolo
Copy link
Member

gziolo commented Oct 14, 2020

It looks like there is no action left. I will close this issue. @Lewiscowles1986, did you manage to resolve your issue by following the recommendation shared?

@gziolo gziolo closed this as completed Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants